pin: better doc, small cleaning

parent c82db2ef
...@@ -2,46 +2,48 @@ package options ...@@ -2,46 +2,48 @@ package options
import "fmt" import "fmt"
// PinAddSettings represent the settings for PinAPI.Add
type PinAddSettings struct { type PinAddSettings struct {
Recursive bool Recursive bool
} }
type TypeSettings struct { // PinLsSettings represent the settings for PinAPI.Ls
Type string
}
type PinLsSettings struct { type PinLsSettings struct {
Type string Type string
} }
// PinIsPinnedSettings represent the settings for PinAPI.IsPinned
type PinIsPinnedSettings struct { type PinIsPinnedSettings struct {
WithType string WithType string
} }
// PinRmSettings represents the settings of pin rm command // PinRmSettings represents the settings for PinAPI.Rm
type PinRmSettings struct { type PinRmSettings struct {
Recursive bool Recursive bool
} }
// PinUpdateSettings represent the settings for PinAPI.Update
type PinUpdateSettings struct { type PinUpdateSettings struct {
Unpin bool Unpin bool
} }
// PinAddOption pin add option func // PinAddOption is the signature of an option for PinAPI.Add
type PinAddOption func(*PinAddSettings) error type PinAddOption func(*PinAddSettings) error
// PinLsOption pin ls option func // PinLsOption is the signature of an option for PinAPI.Ls
type PinLsOption func(*PinLsSettings) error type PinLsOption func(*PinLsSettings) error
// PinIsPinnedOption pin isPinned option func // PinIsPinnedOption is the signature of an option for PinAPI.IsPinned
type PinIsPinnedOption func(*PinIsPinnedSettings) error type PinIsPinnedOption func(*PinIsPinnedSettings) error
// PinRmOption pin rm option func // PinRmOption is the signature of an option for PinAPI.Rm
type PinRmOption func(*PinRmSettings) error type PinRmOption func(*PinRmSettings) error
// PinUpdateOption pin update option func // PinUpdateOption is the signature of an option for PinAPI.Update
type PinUpdateOption func(*PinUpdateSettings) error type PinUpdateOption func(*PinUpdateSettings) error
// PinAddOptions compile a series of PinAddOption into a ready to use
// PinAddSettings and set the default values.
func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) { func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
options := &PinAddSettings{ options := &PinAddSettings{
Recursive: true, Recursive: true,
...@@ -57,6 +59,8 @@ func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) { ...@@ -57,6 +59,8 @@ func PinAddOptions(opts ...PinAddOption) (*PinAddSettings, error) {
return options, nil return options, nil
} }
// PinLsOptions compile a series of PinLsOption into a ready to use
// PinLsSettings and set the default values.
func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) { func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
options := &PinLsSettings{ options := &PinLsSettings{
Type: "all", Type: "all",
...@@ -72,6 +76,8 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) { ...@@ -72,6 +76,8 @@ func PinLsOptions(opts ...PinLsOption) (*PinLsSettings, error) {
return options, nil return options, nil
} }
// PinIsPinnedOptions compile a series of PinIsPinnedOption into a ready to use
// PinIsPinnedSettings and set the default values.
func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error) { func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error) {
options := &PinIsPinnedSettings{ options := &PinIsPinnedSettings{
WithType: "all", WithType: "all",
...@@ -87,7 +93,8 @@ func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error) ...@@ -87,7 +93,8 @@ func PinIsPinnedOptions(opts ...PinIsPinnedOption) (*PinIsPinnedSettings, error)
return options, nil return options, nil
} }
// PinRmOptions pin rm options // PinRmOptions compile a series of PinRmOption into a ready to use
// PinRmSettings and set the default values.
func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) { func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
options := &PinRmSettings{ options := &PinRmSettings{
Recursive: true, Recursive: true,
...@@ -102,6 +109,8 @@ func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) { ...@@ -102,6 +109,8 @@ func PinRmOptions(opts ...PinRmOption) (*PinRmSettings, error) {
return options, nil return options, nil
} }
// PinUpdateOptions compile a series of PinUpdateOption into a ready to use
// PinUpdateSettings and set the default values.
func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) { func PinUpdateOptions(opts ...PinUpdateOption) (*PinUpdateSettings, error) {
options := &PinUpdateSettings{ options := &PinUpdateSettings{
Unpin: true, Unpin: true,
...@@ -122,6 +131,7 @@ type pinOpts struct { ...@@ -122,6 +131,7 @@ type pinOpts struct {
IsPinned pinIsPinnedOpts IsPinned pinIsPinnedOpts
} }
// Pin provide an access to all the options for the Pin API.
var Pin pinOpts var Pin pinOpts
type pinLsOpts struct{} type pinLsOpts struct{}
......
...@@ -546,7 +546,7 @@ func assertIsPinned(t *testing.T, ctx context.Context, api iface.CoreAPI, p path ...@@ -546,7 +546,7 @@ func assertIsPinned(t *testing.T, ctx context.Context, api iface.CoreAPI, p path
t.Helper() t.Helper()
withType, err := opt.Pin.IsPinned.Type(typeStr) withType, err := opt.Pin.IsPinned.Type(typeStr)
if err != nil { if err != nil {
panic("unhandled pin type") t.Fatal("unhandled pin type")
} }
whyPinned, pinned, err := api.Pin().IsPinned(ctx, p, withType) whyPinned, pinned, err := api.Pin().IsPinned(ctx, p, withType)
......
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