[CLI] Accept spaces/user/repo as repo ID prefix shorthand#3929
[CLI] Accept spaces/user/repo as repo ID prefix shorthand#3929
spaces/user/repo as repo ID prefix shorthand#3929Conversation
Rewrite prefixed repo IDs (e.g. `spaces/user/repo` → `user/repo --type space`) at the HFCliTyperGroup level so it works automatically for all commands that accept `--type`/`--repo-type`, without per-command changes. Follows the same pattern as the `--json` → `--format json` rewrite from #3919. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| continue | ||
| parts = arg.split("/", 2) | ||
| if len(parts) == 3 and parts[0] in _REPO_TYPE_PREFIXES: | ||
| prefix_matches.append((i, parts)) |
There was a problem hiding this comment.
Prefix rewriting incorrectly matches non-repo-ID arguments
Medium Severity
_rewrite_repo_type_prefix treats every non-flag argument (except index 0) as a potential prefixed repo ID, but commands like download, upload, and delete-files accept additional positional args (filenames, local paths, patterns) and option values after flags like --revision or --local-dir. A path like models/weights/model.safetensors passed as a filename to hf download, or datasets/train/data.csv passed as local_path to hf upload, would be incorrectly matched, stripped of its prefix, and cause --type to be appended — silently corrupting the argument.
There was a problem hiding this comment.
agree with cursor here, we should scan only repo id positional args.
There was a problem hiding this comment.
Codex suggested to use cmd.params to know which tokens are click.Arguments, and only inspect arguments whose name is repo_id
|
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. |
| continue | ||
| parts = arg.split("/", 2) | ||
| if len(parts) == 3 and parts[0] in _REPO_TYPE_PREFIXES: | ||
| prefix_matches.append((i, parts)) |
There was a problem hiding this comment.
agree with cursor here, we should scan only repo id positional args.
| "spaces": "space", | ||
| "datasets": "dataset", | ||
| "models": "model", | ||
| } |
There was a problem hiding this comment.
we can use constants.REPO_TYPES_MAPPING here
| continue | ||
| parts = arg.split("/", 2) | ||
| if len(parts) == 3 and parts[0] in _REPO_TYPE_PREFIXES: | ||
| prefix_matches.append((i, parts)) |
There was a problem hiding this comment.
Codex suggested to use cmd.params to know which tokens are click.Arguments, and only inspect arguments whose name is repo_id


Summary
Accept repo IDs like
spaces/user/repo,datasets/user/repo,models/user/repoas shorthand foruser/repo --type spaceetc. This is implemented at theHFCliTyperGroup.resolve_command()level, so it works automatically for all commands that accept--type/--repo-type— no per-command changes needed.Follows the same pattern as the
--json→--format jsonrewrite from #3919.--typeflag are provided (ambiguous)--typeoption are unaffectedAddresses #3906 (comment)
Test plan
spaces/user/reporewrites touser/repo --type spaceondownloaddatasets/user/reporewrites touser/repo --type datasetondownloadmodels/user/reporewrites touser/repo --type modelondownload--typeboth provided--repo-typeboth providedrepos settings)--type--jsonshorthand tests still pass🤖 Generated with Claude Code
Note
Medium Risk
Changes global CLI argument rewriting for any command exposing
--type/--repo-type, which could subtly affect parsing of positional arguments and error behavior. Guardrails and tests reduce risk, but regressions could impact multiple commands.Overview
Adds a CLI shorthand so repo IDs can be passed as
spaces/<org>/<repo>,datasets/<org>/<repo>, ormodels/<org>/<repo>, automatically rewriting them to<org>/<repo>plus an implicit--typevalue during command resolution.The rewrite only applies to commands that accept
--type/--repo-type, errors on mixed/ambiguous usage (prefix + explicit type, or conflicting prefixes across args), and extends tests to cover download and nested subcommands while keeping--jsonpass-through behavior intact.Written by Cursor Bugbot for commit 25f7eff. This will update automatically on new commits. Configure here.