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
feat: enables searching pins by name #10412
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for submitting this! I think it's a good idea to search for the exact name matches as a first iteration. In the future, I think it could be nice to have something with regular expressions too. The code looks fine to me and thanks for adding a test.
However, it does not match exactly the idea from #10281. Below you can find some comments of suggestions of what could be changed to make it slightly more generic (using contains instead of equal).
@lidel what do you think? I'm fine either way, but I think searching for something that contains the given name could be more valuable than for exact matches only.
AddToResultKeys := func(c cid.Cid, name, typeStr string) error { | ||
if emittedSet.Visit(c) { | ||
AddToResultKeys := func(c cid.Cid, pinName, typeStr string) error { | ||
if emittedSet.Visit(c) && (name == "" || name == pinName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if replacing by strings.Contains
wouldn't make the search more useful. Would need to import strings
.
if emittedSet.Visit(c) && (name == "" || name == pinName) { | |
if emittedSet.Visit(c) && (name == "" || strings.Contains(pinName, name)) { |
@@ -362,6 +362,7 @@ Example: | |||
cmds.BoolOption(pinQuietOptionName, "q", "Write just hashes of objects."), | |||
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 only pins with the given name."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would align it more with what is said in the initial issue:
cmds.StringOption(pinNameOptionName, "Display only pins with the given name."), | |
cmds.StringOption(pinNameOptionName, "Display pins with names that contain the value provided (case-sensitive, exact match)."), |
Closes #10281.
This PR introduces the possibility to perform a search on pin names (case-sensitive, exact search). The command
ipfs pin ls --name "pinName"
will return all the pins labeled aspinName
.Notes:
displayNames || name != ""
is implemented to prevent redundancy in specifying the--name
option. This ensures that users can simply useipfs ls --name A
instead ofipfs ls --names --name A
.