Skip to content

Include the usage string in Command.to_info_dict - #3816

Open
sahabajalam wants to merge 2 commits into
pallets:mainfrom
sahabajalam:add-usage-to-info-dict
Open

Include the usage string in Command.to_info_dict#3816
sahabajalam wants to merge 2 commits into
pallets:mainfrom
sahabajalam:add-usage-to-info-dict

Conversation

@sahabajalam

Copy link
Copy Markdown

What

Adds a usage key — the output of get_usage() — to every command's to_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_dict already iterates subcommands and calls each child's to_info_dict with 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:

  • the key is added recursively for every command and group, not just the top level;
  • the raw get_usage() output is kept as-is (including the Usage: prefix) — consumers can strip it if they prefer, as the issue's workaround does.

Testing

  • Updated the existing fixtures in tests/test_info_dict.py.
  • Added test_command_usage asserting the recursive behavior through a nested GroupGroupCommand tree, 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

sahabajalam and others added 2 commits August 30, 2026 18:29
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
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.

Add output of get_usage() to get_info_dict()

1 participant