[CLI] Print help when leaf command with required args is called without args#4135
Merged
[CLI] Print help when leaf command with required args is called without args#4135
Conversation
…ut args Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
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. |
Contributor
Author
|
(failing CI is unrelated) |
Contributor
|
This PR has been shipped as part of the v1.13.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hf download(leaf commands with required positional arguments) used to error out withError: Missing argument 'REPO_ID'when called without args. Command groups likehf jobsprint 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.parse_argsin theHFCliCommandclass factory. Commands with no required arguments (e.g.hf version,hf env) keep running normally.--help/-hstill work.Context: https://huggingface.slack.com/archives/C0ACCEFPU9W/p1776414191737639
Before
After
Verified manually that
hf version,hf env,hf download --help, and groups likehf jobsare 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_argsviaHFCliCommandin_cli_utils.py, and adds a regression test assertinghf downloadwithout 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.