Skip to content

Commit

Permalink
fix(cli): unify --name param in ls and add (#10439)
Browse files Browse the repository at this point in the history
This is a cosmetic fix for bug found during testing 0.29.0-rc2.
pin add --name had shorthand -n
pin ls --name had no shorthand, and --names had -n

This unifies -n making it a shorthand for the same parameter in both
`pin ls` and `pin add`.
  • Loading branch information
lidel authored Jun 6, 2024
1 parent 40cf630 commit a07852a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 27 deletions.
6 changes: 3 additions & 3 deletions core/commands/pin/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ Example:
},
Options: []cmds.Option{
cmds.StringOption(pinTypeOptionName, "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\".").WithDefault("all"),
cmds.BoolOption(pinQuietOptionName, "q", "Write just hashes of objects."),
cmds.BoolOption(pinQuietOptionName, "q", "Output only the CIDs of pins."),
cmds.StringOption(pinNameOptionName, "n", "Limit returned pins to ones with names that contain the value provided (case-sensitive, partial match). Implies --names=true."),
cmds.BoolOption(pinStreamOptionName, "s", "Enable streaming of pins as they are discovered."),
cmds.BoolOption(pinNamesOptionName, "n", "Enable displaying pin names (slower)."),
cmds.StringOption(pinNameOptionName, "Display pins with names that contain the value provided (case-sensitive, partial match)."),
cmds.BoolOption(pinNamesOptionName, "Include pin names in the output (slower, disabled by default)."),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
api, err := cmdenv.GetApi(env, req)
Expand Down
9 changes: 7 additions & 2 deletions docs/changelogs/v0.29.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@

#### Add search functionality for pin names

It is now possible to search for pins by name. To do so, use `ipfs pin ls --name "SomeName"`. The search is case-sensitive and will return all pins having a name which contains the exact word provided.
It is now possible to search for pins by name via `ipfs pin ls --name "SomeName"`.
The search is case-sensitive and will return all pins that contain the specified substring in their name.

> [!TIP]
> The `ipfs pin ls -n` is now a shorthand for `ipfs pin ls --name`, mirroring the behavior of `ipfs pin add`.
> See `ipfs pin ls --help` for more information.
#### Customizing `ipfs add` defaults

Expand All @@ -27,7 +32,7 @@ The hash function, CID version, or UnixFS raw leaves and chunker behaviors can b
> [!TIP]
> As a convenience, two CID [profiles](../config.md#profile) are provided: `legacy-cid-v0` and `test-cid-v1`.
> A test profile that defaults to modern CIDv1 can be applied via `ipfs config profile apply test-cid-v1`.
> We encourage users to try it and report any issues.
> We encourage users to try it and report any issues in [kubo#4143](https://github.com/ipfs/kubo/issues/4143).
### 📝 Changelog

Expand Down
47 changes: 25 additions & 22 deletions test/cli/pins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestPins(t *testing.T) {
require.NotContains(t, lsOut, outADetailed)
})

t.Run("test listing pins which contains specific name", func(t *testing.T) {
t.Run("test listing pins with names that contain specific string", func(t *testing.T) {
t.Parallel()

node := harness.NewT(t).NewNode().Init()
Expand All @@ -254,27 +254,30 @@ func TestPins(t *testing.T) {
outB := cidBStr + " recursive testPin"
outC := cidCStr + " recursive randPin"

_ = node.IPFS("pin", "add", "--name", "testPin", cidAStr)
lsOut := pinLs(node, "-t=recursive", "--name=test")
require.Contains(t, lsOut, outA)
lsOut = pinLs(node, "-t=recursive", "--name=randomLabel")
require.NotContains(t, lsOut, outA)

_ = node.IPFS("pin", "add", "--name", "testPin", cidBStr)
lsOut = pinLs(node, "-t=recursive", "--name=test")
require.Contains(t, lsOut, outA)
require.Contains(t, lsOut, outB)

_ = node.IPFS("pin", "add", "--name", "randPin", cidCStr)
lsOut = pinLs(node, "-t=recursive", "--name=rand")
require.NotContains(t, lsOut, outA)
require.NotContains(t, lsOut, outB)
require.Contains(t, lsOut, outC)

lsOut = pinLs(node, "-t=recursive", "--name=testPin")
require.Contains(t, lsOut, outA)
require.Contains(t, lsOut, outB)
require.NotContains(t, lsOut, outC)
// make sure both -n and --name work
for _, nameParam := range []string{"--name", "-n"} {
_ = node.IPFS("pin", "add", "--name", "testPin", cidAStr)
lsOut := pinLs(node, "-t=recursive", nameParam+"=test")
require.Contains(t, lsOut, outA)
lsOut = pinLs(node, "-t=recursive", nameParam+"=randomLabel")
require.NotContains(t, lsOut, outA)

_ = node.IPFS("pin", "add", "--name", "testPin", cidBStr)
lsOut = pinLs(node, "-t=recursive", nameParam+"=test")
require.Contains(t, lsOut, outA)
require.Contains(t, lsOut, outB)

_ = node.IPFS("pin", "add", "--name", "randPin", cidCStr)
lsOut = pinLs(node, "-t=recursive", nameParam+"=rand")
require.NotContains(t, lsOut, outA)
require.NotContains(t, lsOut, outB)
require.Contains(t, lsOut, outC)

lsOut = pinLs(node, "-t=recursive", nameParam+"=testPin")
require.Contains(t, lsOut, outA)
require.Contains(t, lsOut, outB)
require.NotContains(t, lsOut, outC)
}
})

t.Run("test overwriting pin with name", func(t *testing.T) {
Expand Down

0 comments on commit a07852a

Please sign in to comment.