Skip to content

[CLI] Print help when leaf command with required args is called without args#4135

Merged
Wauplin merged 1 commit into
mainfrom
cli-no-args-help
Apr 27, 2026
Merged

[CLI] Print help when leaf command with required args is called without args#4135
Wauplin merged 1 commit into
mainfrom
cli-no-args-help

Conversation

@Wauplin

@Wauplin Wauplin commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Commands like hf download (leaf commands with required positional arguments) used to error out with Error: Missing argument 'REPO_ID' when called without args. Command groups like hf jobs print their help instead. This PR makes leaf commands behave the same way: if a command has at least one required argument and is invoked with no args, print help and exit 0.
  • Implemented by overriding parse_args in the HFCliCommand class factory. Commands with no required arguments (e.g. hf version, hf env) keep running normally. --help / -h still work.

Context: https://huggingface.slack.com/archives/C0ACCEFPU9W/p1776414191737639

Before

$ hf download
Usage: hf download [OPTIONS] REPO_ID [FILENAMES]...
Try 'hf download -h' for help.

Error: Missing argument 'REPO_ID'.

After

$ hf download
Usage: hf download [OPTIONS] REPO_ID [FILENAMES]...

  Download files from the Hub.

Arguments:
  REPO_ID         The ID of the repo (e.g. `username/repo-name` or
                  `spaces/username/repo-name`).  [required]
  [FILENAMES]...  Files to download (e.g. `config.json`,
                  `data/metadata.jsonl`).
...

Verified manually that hf version, hf env, hf download --help, and groups like hf jobs are unaffected.

🤖 Generated with Claude Code


Note

Low Risk
Low risk: small CLI UX change confined to argument parsing for leaf commands, with a targeted test to guard behavior. Main risk is unintended help/exit behavior for commands that rely on empty-args invocation, but it’s gated on having required positional args.

Overview
Leaf CLI commands with required positional arguments now print their help and exit 0 when invoked with no args (e.g. hf download), matching how command groups behave.

Implemented by overriding TyperCommand.parse_args via HFCliCommand in _cli_utils.py, and adds a regression test asserting hf download without args shows usage/help instead of a missing-argument error.

Reviewed by Cursor Bugbot for commit 81ac8ff. Bugbot is set up for automated code reviews on this repo. Configure here.

…ut args

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Wauplin Wauplin requested a review from hanouticelina April 23, 2026 14:36
@bot-ci-comment

Copy link
Copy Markdown

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.

@Wauplin

Wauplin commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator Author

(failing CI is unrelated)

@hanouticelina hanouticelina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@Wauplin Wauplin merged commit ceaf4dc into main Apr 27, 2026
17 of 21 checks passed
@Wauplin Wauplin deleted the cli-no-args-help branch April 27, 2026 11:26
@huggingface-hub-bot

Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.13.0 release.

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