-
Notifications
You must be signed in to change notification settings - Fork 854
Add sort and limit parameters in hf cache ls #3510
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
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| ``` | ||
|
|
||
| The command supports several output formats for scripting: `--format json` prints structured objects, `--format csv` writes comma-separated rows, and `--quiet` prints only IDs. Combine these with `--cache-dir` to target alternative cache locations. See the [Manage your cache](./manage-cache) guide for advanced workflows. | ||
| The command supports several output formats for scripting: `--format json` prints structured objects, `--format csv` writes comma-separated rows, and `--quiet` prints only IDs. Use `--sort` to order entries by `accessed`, `modified`, `name`, or `size` (append `:asc` or `:desc` to control order), and `--limit` to restrict results to the top N entries. Combine these with `--cache-dir` to target alternative cache locations. See the [Manage your cache](./manage-cache) guide for advanced workflows. |
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.
personal preference to have --order asc|desc instead of having a suffix (more intuitive imo). wdyt?
hf cache ls --sort accessed --order desc 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 tend to find it quite verbose to be honest.
At first I thought we should go for --sort=accessed / --sort=-accessed like some other CLIs but I find it less explicit, hence the solution I suggested in this PR. If you feel strongly about it I can change
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.
Not a strong opinion here, I was mainly suggesting this for better discoverability (and readability). Using --sort accessed --order desc reads more like plain English 😄 and fwiw, gh cache CLI uses a combination of --sort and --order options. Also I was thinking that having a separate --order flag could also help with shell completion (for ["asc", "desc"]) but it turns out we already have that covered:
Screen.Recording.2025-10-31.at.16.02.20.mov
( 👍 i definitely agree on not doing something like --sort=accessed / --sort=-accessed)
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.
it turns out we already have that covered:
That almost the only addition I've made manually to Cursor output (the auto-generation of the string enum) 😄
gh cache CLI uses a combination of --sort and --order options.
Do you know what's happening when --order is passed without --sort? Is it just ignored? Also if we have both arguments, someone could be tempted to do a --order size if they haven't seen the --sort parameter yet. (that was my reason to avoid having several args)
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.
Do you know what's happening when --order is passed without --sort? Is it just ignored?
not sure and i can't test locally (i don't have any gh cache 😄) but i think gh will default the sort field to the default value (last_accessed_at) https://cli.github.com/manual/gh_cache_list
Also if we have both arguments, someone could be tempted to do a --order size if they haven't seen the --sort parameter yet.
yes, makes sense!
hanouticelina
left a comment
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.
very nice! could you ask cursor to generate a small test for at least one sorting key? 😄
As a matter of fact it generated plenty of tests that I removed (waaaayyyy too specific) but I was sure I kept one. Anyway, I added one back manually |
hanouticelina
left a comment
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.
Thank you!
Disclaimer:
Code changes and PR description auto-generated by Cursor Composer (2.0 Agent mode). Initial prompt I gave:
What a pity, I had to run
make styleby myself 😄 (also, I've tested the CLI myself on my machine)Summary
This PR adds two new parameters to the
hf cache lscommand to enable sorting and limiting cache entries, making it easier to find and manage cached repositories and revisions.Changes
New Features
--sortparameter: Sort cache entries by various keysaccessed,modified,name,size:ascor:desc(e.g.,modified:asc)accessed,modified,size→ descending (newest/biggest first)name→ ascending (alphabetical)--limitparameter: Limit the number of results returnedImplementation Details
compile_cache_sort()function to parse and validate sort expressions_SORT_KEYSand_SORT_PATTERNconstants for validationExamples
Testing
:asc/:desc)Documentation
docs/source/en/guides/cli.mdwith brief mention of new optionsdocs/source/en/guides/manage-cache.mdwith usage examplesBenefits
Backward Compatibility
✅ Fully backward compatible - all new parameters are optional