cmds/pin: use coreapi/pin
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@3e1cd71bb97f70a6309fa31f3d9e719c7b38f254 This commit was moved from ipfs/boxo@6b2d6ab3cdddb3db4b653e82ac78560e2c1b842f
Overbool committed
Dec 13, 2018 at 23:02 UTC
0f40b6847509dd7a52c54d9931dc9230e39ed4f3
2 files changed
+36
-2
core/coreiface/options/pin.go
+35
-1
@@ -8,12 +8,23 @@ type PinLsSettings struct {
8
Type string
9
}
10
11
+// PinRmSettings represents the settings of pin rm command
12
+type PinRmSettings struct {
13
+ Recursive bool
14
+ Force bool
15
+}
16
+
17
type PinUpdateSettings struct {
18
Unpin bool
19
}
20
21
type PinAddOption func(*PinAddSettings) error
16
-type PinLsOption func(settings *PinLsSettings) error
22
+
23
+// PinRmOption pin rm option func
24
+type PinRmOption func(*PinRmSettings) error
25
+
26
+// PinLsOption pin ls option func
27
+type PinLsOption func(*PinLsSettings) error
28
type PinUpdateOption func(*PinUpdateSettings) error
29
30
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
@@ -31,6 +42,21 @@ func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
42
return options, nil
43
}
44
45
+// PinRmOptions pin rm options
46
+func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
47
+ options := &PinRmSettings{
48
+ Recursive: true,
49
+ }
50
+
51
+ for _, opt := range opts {
52
+ if err := opt(options); err != nil {
53
+ return nil, err
54
+ }
55
+ }
56
+
57
+ return options, nil
58
+}
59
+
60
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
61
options := &PinLsSettings{
62
Type: "all",
@@ -102,6 +128,14 @@ func (pinOpts) Recursive(recursive bool) PinAddOption {
128
}
129
}
130
131
+// RmRecursive is an option for Pin.Rm
132
+func (pinOpts) RmRecursive(recursive bool) PinRmOption {
133
+ return func(settings *PinRmSettings) error {
134
+ settings.Recursive = recursive
135
+ return nil
136
+ }
137
+}
138
+
139
// Type is an option for Pin.Ls which allows to specify which pin types should
140
// be returned
141
//
core/coreiface/pin.go
+1
-1
@@ -43,7 +43,7 @@ type PinAPI interface {
43
Ls(context.Context, ...options.PinLsOption) ([]Pin, error)
44
45
// Rm removes pin for object specified by the path
46
- Rm(context.Context, Path) error
46
+ Rm(context.Context, Path, ...options.PinRmOption) error
47
48
// Update changes one pin to another, skipping checks for matching paths in
49
// the old tree