@cryptotaxi247 / kubo / commits / a07852a3f

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

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`.

Marcin Rataj committed Jun 6, 2024 at 22:19 UTC a07852a3f0294974b802923fb136885ad077384e
3 files changed +35 -27
core/commands/pin/pin.go
+3 -3
@@ -359,10 +359,10 @@ Example:
359 },
360 Options: []cmds.Option{
361 cmds.StringOption(pinTypeOptionName, "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\".").WithDefault("all"),
362 - cmds.BoolOption(pinQuietOptionName, "q", "Write just hashes of objects."),
362 + cmds.BoolOption(pinQuietOptionName, "q", "Output only the CIDs of pins."),
363 + cmds.StringOption(pinNameOptionName, "n", "Limit returned pins to ones with names that contain the value provided (case-sensitive, partial match). Implies --names=true."),
364 cmds.BoolOption(pinStreamOptionName, "s", "Enable streaming of pins as they are discovered."),
364 - cmds.BoolOption(pinNamesOptionName, "n", "Enable displaying pin names (slower)."),
365 - cmds.StringOption(pinNameOptionName, "Display pins with names that contain the value provided (case-sensitive, partial match)."),
365 + cmds.BoolOption(pinNamesOptionName, "Include pin names in the output (slower, disabled by default)."),
366 },
367 Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
368 api, err := cmdenv.GetApi(env, req)
docs/changelogs/v0.29.md
+7 -2
@@ -17,7 +17,12 @@
17
18 #### Add search functionality for pin names
19
20 -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.
20 +It is now possible to search for pins by name via `ipfs pin ls --name "SomeName"`.
21 +The search is case-sensitive and will return all pins that contain the specified substring in their name.
22 +
23 +> [!TIP]
24 +> The `ipfs pin ls -n` is now a shorthand for `ipfs pin ls --name`, mirroring the behavior of `ipfs pin add`.
25 +> See `ipfs pin ls --help` for more information.
26
27 #### Customizing `ipfs add` defaults
28
@@ -27,7 +32,7 @@ The hash function, CID version, or UnixFS raw leaves and chunker behaviors can b
32 > [!TIP]
33 > As a convenience, two CID [profiles](../config.md#profile) are provided: `legacy-cid-v0` and `test-cid-v1`.
34 > A test profile that defaults to modern CIDv1 can be applied via `ipfs config profile apply test-cid-v1`.
30 -> We encourage users to try it and report any issues.
35 +> We encourage users to try it and report any issues in [kubo#4143](https://github.com/ipfs/kubo/issues/4143).
36
37 ### 📝 Changelog
38
test/cli/pins_test.go
+25 -22
@@ -242,7 +242,7 @@ func TestPins(t *testing.T) {
242 require.NotContains(t, lsOut, outADetailed)
243 })
244
245 - t.Run("test listing pins which contains specific name", func(t *testing.T) {
245 + t.Run("test listing pins with names that contain specific string", func(t *testing.T) {
246 t.Parallel()
247
248 node := harness.NewT(t).NewNode().Init()
@@ -254,27 +254,30 @@ func TestPins(t *testing.T) {
254 outB := cidBStr + " recursive testPin"
255 outC := cidCStr + " recursive randPin"
256
257 - _ = node.IPFS("pin", "add", "--name", "testPin", cidAStr)
258 - lsOut := pinLs(node, "-t=recursive", "--name=test")
259 - require.Contains(t, lsOut, outA)
260 - lsOut = pinLs(node, "-t=recursive", "--name=randomLabel")
261 - require.NotContains(t, lsOut, outA)
262 -
263 - _ = node.IPFS("pin", "add", "--name", "testPin", cidBStr)
264 - lsOut = pinLs(node, "-t=recursive", "--name=test")
265 - require.Contains(t, lsOut, outA)
266 - require.Contains(t, lsOut, outB)
267 -
268 - _ = node.IPFS("pin", "add", "--name", "randPin", cidCStr)
269 - lsOut = pinLs(node, "-t=recursive", "--name=rand")
270 - require.NotContains(t, lsOut, outA)
271 - require.NotContains(t, lsOut, outB)
272 - require.Contains(t, lsOut, outC)
273 -
274 - lsOut = pinLs(node, "-t=recursive", "--name=testPin")
275 - require.Contains(t, lsOut, outA)
276 - require.Contains(t, lsOut, outB)
277 - require.NotContains(t, lsOut, outC)
257 + // make sure both -n and --name work
258 + for _, nameParam := range []string{"--name", "-n"} {
259 + _ = node.IPFS("pin", "add", "--name", "testPin", cidAStr)
260 + lsOut := pinLs(node, "-t=recursive", nameParam+"=test")
261 + require.Contains(t, lsOut, outA)
262 + lsOut = pinLs(node, "-t=recursive", nameParam+"=randomLabel")
263 + require.NotContains(t, lsOut, outA)
264 +
265 + _ = node.IPFS("pin", "add", "--name", "testPin", cidBStr)
266 + lsOut = pinLs(node, "-t=recursive", nameParam+"=test")
267 + require.Contains(t, lsOut, outA)
268 + require.Contains(t, lsOut, outB)
269 +
270 + _ = node.IPFS("pin", "add", "--name", "randPin", cidCStr)
271 + lsOut = pinLs(node, "-t=recursive", nameParam+"=rand")
272 + require.NotContains(t, lsOut, outA)
273 + require.NotContains(t, lsOut, outB)
274 + require.Contains(t, lsOut, outC)
275 +
276 + lsOut = pinLs(node, "-t=recursive", nameParam+"=testPin")
277 + require.Contains(t, lsOut, outA)
278 + require.Contains(t, lsOut, outB)
279 + require.NotContains(t, lsOut, outC)
280 + }
281 })
282
283 t.Run("test overwriting pin with name", func(t *testing.T) {