Include the usage string in Command.to_info_dict - #3816
Open
sahabajalam wants to merge 2 commits into
Open
Conversation
Add a "usage" key with the output of get_usage() to every command's info dict. Group.to_info_dict already recurses into subcommands with proper sub-contexts, so every command and group at any depth gets its usage with the full command path — no extra traversal needed. Closes pallets#2992 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016JWf18rkGASF2oREqHpmqX
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016JWf18rkGASF2oREqHpmqX
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.
What
Adds a
usagekey — the output ofget_usage()— to every command'sto_info_dict()output, so tools generating user-facing documentation from the info dict no longer need to hardcode or manually reconstruct usage lines.How
A single line in
Command.to_info_dict.Group.to_info_dictalready iterates subcommands and calls each child'sto_info_dictwith a proper sub-context (ctx._make_sub_context), so the key appears recursively at every depth with the full command path (e.g.Usage: cli sub hello [OPTIONS]) — no additional traversal needed.Design choices, matching the discussion in #2992:
get_usage()output is kept as-is (including theUsage:prefix) — consumers can strip it if they prefer, as the issue's workaround does.Testing
tests/test_info_dict.py.test_command_usageasserting the recursive behavior through a nestedGroup→Group→Commandtree, including full command paths.pytest tests/test_info_dict.py: 29 passed.Closes #2992
Transparency note: this change was produced by an automated coding pipeline (Claude Code) as part of a tooling experiment, then human-reviewed — the recursion behavior and tests were verified independently before submitting. Happy to adjust anything to fit maintainer preferences.
🤖 Generated with Claude Code
https://claude.ai/code/session_016JWf18rkGASF2oREqHpmqX