Commit 3e1cd71b authored by Overbool's avatar Overbool Committed by Steven Allen

cmds/pin: use coreapi/pin

License: MIT
Signed-off-by: default avatarOverbool <overbool.xu@gmail.com>
parent 3cc65786
......@@ -8,12 +8,23 @@ type PinLsSettings struct {
Type string
}
// PinRmSettings represents the settings of pin rm command
type PinRmSettings struct {
Recursive bool
Force bool
}
type PinUpdateSettings struct {
Unpin bool
}
type PinAddOption func(*PinAddSettings) error
type PinLsOption func(settings *PinLsSettings) error
// PinRmOption pin rm option func
type PinRmOption func(*PinRmSettings) error
// PinLsOption pin ls option func
type PinLsOption func(*PinLsSettings) error
type PinUpdateOption func(*PinUpdateSettings) error
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
......@@ -31,6 +42,21 @@ func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
return options, nil
}
// PinRmOptions pin rm options
func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
options := &PinRmSettings{
Recursive: true,
}
for _, opt := range opts {
if err := opt(options); err != nil {
return nil, err
}
}
return options, nil
}
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
options := &PinLsSettings{
Type: "all",
......@@ -102,6 +128,14 @@ func (pinOpts) Recursive(recursive bool) PinAddOption {
}
}
// RmRecursive is an option for Pin.Rm
func (pinOpts) RmRecursive(recursive bool) PinRmOption {
return func(settings *PinRmSettings) error {
settings.Recursive = recursive
return nil
}
}
// Type is an option for Pin.Ls which allows to specify which pin types should
// be returned
//
......
......@@ -43,7 +43,7 @@ type PinAPI interface {
Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
// Rm removes pin for object specified by the path
Rm(context.Context, Path) error
Rm(context.Context, Path, ...options.PinRmOption) error
// Update changes one pin to another, skipping checks for matching paths in
// the old tree
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment