diff --git a/core/coreapi/interface/options/pin.go b/core/coreapi/interface/options/pin.go index 680ed391d..7cb4d09d2 100644 --- a/core/coreapi/interface/options/pin.go +++ b/core/coreapi/interface/options/pin.go @@ -61,10 +61,38 @@ func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) { return options, nil } -type pinOpts struct{} +type pinType struct{} + +type pinOpts struct { + Type pinType +} var Pin pinOpts +// All is an option for Pin.Ls which will make it return all pins. It is +// the default +func (_ pinType) All() PinLsOption { + return Pin.pinType("all") +} + +// Recursive is an option for Pin.Ls which will make it only return recursive +// pins +func (_ pinType) Recursive() PinLsOption { + return Pin.pinType("recursive") +} + +// Direct is an option for Pin.Ls which will make it only return direct (non +// recursive) pins +func (_ pinType) Direct() PinLsOption { + return Pin.pinType("direct") +} + +// Indirect is an option for Pin.Ls which will make it only return indirect pins +// (objects referenced by other recursively pinned objects) +func (_ pinType) Indirect() PinLsOption { + return Pin.pinType("indirect") +} + // Recursive is an option for Pin.Add which specifies whether to pin an entire // object tree or just one object. Default: true func (_ pinOpts) Recursive(recucsive bool) PinAddOption { @@ -83,7 +111,7 @@ func (_ pinOpts) Recursive(recucsive bool) PinAddOption { // * "indirect" - indirectly pinned objects (referenced by recursively pinned // objects) // * "all" - all pinned objects (default) -func (_ pinOpts) Type(t string) PinLsOption { +func (_ pinOpts) pinType(t string) PinLsOption { return func(settings *PinLsSettings) error { settings.Type = t return nil diff --git a/core/coreapi/pin_test.go b/core/coreapi/pin_test.go index 5f3b5d855..936bae3bd 100644 --- a/core/coreapi/pin_test.go +++ b/core/coreapi/pin_test.go @@ -121,7 +121,7 @@ func TestPinRecursive(t *testing.T) { t.Errorf("unexpected pin list len: %d", len(list)) } - list, err = api.Pin().Ls(ctx, opt.Pin.Type("direct")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Direct()) if err != nil { t.Fatal(err) } @@ -134,7 +134,7 @@ func TestPinRecursive(t *testing.T) { t.Error("unexpected path") } - list, err = api.Pin().Ls(ctx, opt.Pin.Type("recursive")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Recursive()) if err != nil { t.Fatal(err) } @@ -147,7 +147,7 @@ func TestPinRecursive(t *testing.T) { t.Error("unexpected path") } - list, err = api.Pin().Ls(ctx, opt.Pin.Type("indirect")) + list, err = api.Pin().Ls(ctx, opt.Pin.Type.Indirect()) if err != nil { t.Fatal(err) }