Skip to content

[CLI] Accept spaces/user/repo as repo ID prefix shorthand#3929

Open
Wauplin wants to merge 1 commit intomainfrom
cli/repo-prefix-shorthand
Open

[CLI] Accept spaces/user/repo as repo ID prefix shorthand#3929
Wauplin wants to merge 1 commit intomainfrom
cli/repo-prefix-shorthand

Conversation

@Wauplin
Copy link
Contributor

@Wauplin Wauplin commented Mar 13, 2026

Summary

Accept repo IDs like spaces/user/repo, datasets/user/repo, models/user/repo as shorthand for user/repo --type space etc. This is implemented at the HFCliTyperGroup.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 json rewrite from #3919.

# before
hf download user/my-space --type space
hf discussions list user/my-dataset --type dataset

# after
hf download spaces/user/my-space
hf discussions list datasets/user/my-dataset
  • Error if both a prefix and explicit --type flag are provided (ambiguous)
  • Error if multiple prefixed args disagree on the type
  • Commands without --type option are unaffected

Addresses #3906 (comment)

Test plan

  • spaces/user/repo rewrites to user/repo --type space on download
  • datasets/user/repo rewrites to user/repo --type dataset on download
  • models/user/repo rewrites to user/repo --type model on download
  • Error when prefix + explicit --type both provided
  • Error when prefix + explicit --repo-type both provided
  • Normal repo IDs (no prefix) unchanged
  • Works on nested subcommands (repos settings)
  • Not applied on commands without --type
  • Existing --json shorthand 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>, or models/<org>/<repo>, automatically rewriting them to <org>/<repo> plus an implicit --type value 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 --json pass-through behavior intact.

Written by Cursor Bugbot for commit 25f7eff. This will update automatically on new commits. Configure here.

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>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with cursor here, we should scan only repo id positional args.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex suggested to use cmd.params to know which tokens are click.Arguments, and only inspect arguments whose name is repo_id

@bot-ci-comment
Copy link

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.

Copy link
Contributor

@hanouticelina hanouticelina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!

continue
parts = arg.split("/", 2)
if len(parts) == 3 and parts[0] in _REPO_TYPE_PREFIXES:
prefix_matches.append((i, parts))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree with cursor here, we should scan only repo id positional args.

"spaces": "space",
"datasets": "dataset",
"models": "model",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex suggested to use cmd.params to know which tokens are click.Arguments, and only inspect arguments whose name is repo_id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants