pin: better doc, small cleaning
This commit was moved from ipfs/interface-go-ipfs-core@478caf05ab8fd3b33ae80f8792be2cb7c7a92b45 This commit was moved from ipfs/boxo@bffa011f0a0f01646bcecbc003552941ca31860b
Michael Muré committed
Mar 30, 2020 at 16:20 UTC
7f07bf09966647107c25bbe8e60be1803c7496fb
2 files changed
+22
-12
core/coreiface/options/pin.go
+21
-11
@@ -2,46 +2,48 @@ package options
2
3
import "fmt"
4
5
+// PinAddSettings represent the settings for PinAPI.Add
6
type PinAddSettings struct {
7
Recursive bool
8
}
9
9
-type TypeSettings struct {
10
- Type string
11
-}
12
-
10
+// PinLsSettings represent the settings for PinAPI.Ls
11
type PinLsSettings struct {
12
Type string
13
}
14
15
+// PinIsPinnedSettings represent the settings for PinAPI.IsPinned
16
type PinIsPinnedSettings struct {
17
WithType string
18
}
19
21
-// PinRmSettings represents the settings of pin rm command
20
+// PinRmSettings represents the settings for PinAPI.Rm
21
type PinRmSettings struct {
22
Recursive bool
23
}
24
25
+// PinUpdateSettings represent the settings for PinAPI.Update
26
type PinUpdateSettings struct {
27
Unpin bool
28
}
29
30
-// PinAddOption pin add option func
30
+// PinAddOption is the signature of an option for PinAPI.Add
31
type PinAddOption func(*PinAddSettings) error
32
33
-// PinLsOption pin ls option func
33
+// PinLsOption is the signature of an option for PinAPI.Ls
34
type PinLsOption func(*PinLsSettings) error
35
36
-// PinIsPinnedOption pin isPinned option func
36
+// PinIsPinnedOption is the signature of an option for PinAPI.IsPinned
37
type PinIsPinnedOption func(*PinIsPinnedSettings) error
38
39
-// PinRmOption pin rm option func
39
+// PinRmOption is the signature of an option for PinAPI.Rm
40
type PinRmOption func(*PinRmSettings) error
41
42
-// PinUpdateOption pin update option func
42
+// PinUpdateOption is the signature of an option for PinAPI.Update
43
type PinUpdateOption func(*PinUpdateSettings) error
44
45
+// PinAddOptions compile a series of PinAddOption into a ready to use
46
+// PinAddSettings and set the default values.
47
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
48
options := &PinAddSettings{
49
Recursive: true,
@@ -57,6 +59,8 @@ func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
59
return options, nil
60
}
61
62
+// PinLsOptions compile a series of PinLsOption into a ready to use
63
+// PinLsSettings and set the default values.
64
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
65
options := &PinLsSettings{
66
Type: "all",
@@ -72,6 +76,8 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
76
return options, nil
77
}
78
79
+// PinIsPinnedOptions compile a series of PinIsPinnedOption into a ready to use
80
+// PinIsPinnedSettings and set the default values.
81
func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error) {
82
options := &PinIsPinnedSettings{
83
WithType: "all",
@@ -87,7 +93,8 @@ func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error)
93
return options, nil
94
}
95
90
-// PinRmOptions pin rm options
96
+// PinRmOptions compile a series of PinRmOption into a ready to use
97
+// PinRmSettings and set the default values.
98
func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
99
options := &PinRmSettings{
100
Recursive: true,
@@ -102,6 +109,8 @@ func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
109
return options, nil
110
}
111
112
+// PinUpdateOptions compile a series of PinUpdateOption into a ready to use
113
+// PinUpdateSettings and set the default values.
114
func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
115
options := &PinUpdateSettings{
116
Unpin: true,
@@ -122,6 +131,7 @@ type pinOpts struct {
131
IsPinned pinIsPinnedOpts
132
}
133
134
+// Pin provide an access to all the options for the Pin API.
135
var Pin pinOpts
136
137
type pinLsOpts struct{}
core/coreiface/tests/pin.go
+1
-1
@@ -546,7 +546,7 @@ func assertIsPinned(t *testing.T, ctx context.Context, api iface.CoreAPI, p path
546
t.Helper()
547
withType, err := opt.Pin.IsPinned.Type(typeStr)
548
if err != nil {
549
- panic("unhandled pin type")
549
+ t.Fatal("unhandled pin type")
550
}
551
552
whyPinned, pinned, err := api.Pin().IsPinned(ctx, p, withType)