Skip to content

Commit

Permalink
refactor: rename labels to names
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jan 2, 2024
1 parent ad47d0c commit 79c90b7
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 23 deletions.
13 changes: 6 additions & 7 deletions core/commands/pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type AddPinOutput struct {
}

const (
pinLabelOptionName = "label"
pinRecursiveOptionName = "recursive"
pinProgressOptionName = "progress"
)
Expand All @@ -66,7 +65,7 @@ var addPinCmd = &cmds.Command{
Options: []cmds.Option{
cmds.BoolOption(pinRecursiveOptionName, "r", "Recursively pin the object linked to by the specified object(s).").WithDefault(true),
cmds.BoolOption(pinProgressOptionName, "Show progress"),
cmds.StringOption(pinLabelOptionName, "l", "Label to add to the object(s) to be pinned"),
cmds.StringOption(pinNameOptionName, "n", "An optional name for the pin(s)."),
},
Type: AddPinOutput{},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
Expand All @@ -77,7 +76,7 @@ var addPinCmd = &cmds.Command{

// set recursive flag
recursive, _ := req.Options[pinRecursiveOptionName].(bool)
label, _ := req.Options[pinLabelOptionName].(string)
name, _ := req.Options[pinNameOptionName].(string)
showProgress, _ := req.Options[pinProgressOptionName].(bool)

if err := req.ParseBodyArgs(); err != nil {
Expand All @@ -90,7 +89,7 @@ var addPinCmd = &cmds.Command{
}

if !showProgress {
added, err := pinAddMany(req.Context, api, enc, req.Arguments, recursive, label)
added, err := pinAddMany(req.Context, api, enc, req.Arguments, recursive, name)
if err != nil {
return err
}
Expand All @@ -108,7 +107,7 @@ var addPinCmd = &cmds.Command{

ch := make(chan pinResult, 1)
go func() {
added, err := pinAddMany(ctx, api, enc, req.Arguments, recursive, label)
added, err := pinAddMany(ctx, api, enc, req.Arguments, recursive, name)
ch <- pinResult{pins: added, err: err}
}()

Expand Down Expand Up @@ -184,7 +183,7 @@ var addPinCmd = &cmds.Command{
},
}

func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder, paths []string, recursive bool, label string) ([]string, error) {
func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder, paths []string, recursive bool, name string) ([]string, error) {
added := make([]string, len(paths))
for i, b := range paths {
p, err := cmdutils.PathOrCidPath(b)
Expand All @@ -197,7 +196,7 @@ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder,
return nil, err
}

if err := api.Pin().Add(ctx, rp, options.Pin.Recursive(recursive), options.Pin.Label(label)); err != nil {
if err := api.Pin().Add(ctx, rp, options.Pin.Recursive(recursive), options.Pin.Name(name)); err != nil {
return nil, err
}
added[i] = enc.Encode(rp.RootCid())
Expand Down
6 changes: 3 additions & 3 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOp

defer api.blockstore.PinLock(ctx).Unlock(ctx)

err = api.pinning.Pin(ctx, dagNode, settings.Recursive, settings.Label)
err = api.pinning.Pin(ctx, dagNode, settings.Recursive, settings.Name)
if err != nil {
return fmt.Errorf("pin: %s", err)
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreifac
out <- &pinInfo{err: streamedCid.Err}
return
}
if err = AddToResultKeys(streamedCid.Pin.Key, streamedCid.Pin.Label, "recursive"); err != nil {
if err = AddToResultKeys(streamedCid.Pin.Key, streamedCid.Pin.Name, "recursive"); err != nil {
out <- &pinInfo{err: err}
return
}
Expand All @@ -320,7 +320,7 @@ func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreifac
out <- &pinInfo{err: streamedCid.Err}
return
}
if err = AddToResultKeys(streamedCid.Pin.Key, streamedCid.Pin.Label, "direct"); err != nil {
if err = AddToResultKeys(streamedCid.Pin.Key, streamedCid.Pin.Name, "direct"); err != nil {
out <- &pinInfo{err: err}
return
}
Expand Down
8 changes: 4 additions & 4 deletions core/coreiface/options/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "fmt"
// PinAddSettings represent the settings for PinAPI.Add
type PinAddSettings struct {
Recursive bool
Label string
Name string
}

// PinLsSettings represent the settings for PinAPI.Ls
Expand Down Expand Up @@ -264,10 +264,10 @@ func (pinOpts) Recursive(recursive bool) PinAddOption {
}
}

// Label is an option for Pin.Add which specifies a label to add to the pin.
func (pinOpts) Label(label string) PinAddOption {
// Name is an option for Pin.Add which specifies an optional name to add to the pin.
func (pinOpts) Name(name string) PinAddOption {
return func(settings *PinAddSettings) error {
settings.Label = label
settings.Name = name
return nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/kubo-as-a-library/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go 1.20
replace github.com/ipfs/kubo => ./../../..

require (
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
github.com/libp2p/go-libp2p v0.32.2
github.com/multiformats/go-multiaddr v0.12.0
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/kubo-as-a-library/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705 h1:4DdhReoM3GZV/r1Qj+WkNbJhx06kFo88gxNF82XmJ6o=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58 h1:tffEyCiC1mW0wv1CPfynSNudmhDrsA4idEaHZ2HZ1eQ=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/ipfs-shipyard/nopfs v0.0.12-0.20231027223058-cde3b5ba964c
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58
github.com/ipfs/go-block-format v0.2.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-cidutil v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705 h1:4DdhReoM3GZV/r1Qj+WkNbJhx06kFo88gxNF82XmJ6o=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58 h1:tffEyCiC1mW0wv1CPfynSNudmhDrsA4idEaHZ2HZ1eQ=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
Expand Down
2 changes: 1 addition & 1 deletion test/dependencies/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ require (
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705 // indirect
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58 // indirect
github.com/ipfs/go-block-format v0.2.0 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions test/dependencies/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705 h1:4DdhReoM3GZV/r1Qj+WkNbJhx06kFo88gxNF82XmJ6o=
github.com/ipfs/boxo v0.16.1-0.20231215092939-544358941705/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58 h1:tffEyCiC1mW0wv1CPfynSNudmhDrsA4idEaHZ2HZ1eQ=
github.com/ipfs/boxo v0.16.1-0.20240102110230-a787fdd18a58/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs=
github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down

0 comments on commit 79c90b7

Please sign in to comment.