Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): unify --name shorthand in pin ls and pin add #10439

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading