Skip to content

[v2] Add --help parameter for all CLI commands - #10630

Open
kdaily wants to merge 2 commits into
v2from
kdaily-feature-help-parameter
Open

[v2] Add --help parameter for all CLI commands#10630
kdaily wants to merge 2 commits into
v2from
kdaily-feature-help-parameter

Conversation

@kdaily

@kdaily kdaily commented Sep 10, 2026

Copy link
Copy Markdown
Member

Issue #, if available:

Description of changes:

Adds a --help parameter that renders the same help as the existing help subcommand, on every command: the top-level aws, a service (aws ec2 --help), an operation (aws ec2 describe-instances --help), and custom/nested commands (aws configure get --help). The help subcommand is unchanged.

Implementation

Help intent is resolved before normal argument binding.

  • New helpers in awscli/argparser.py detect and strip the exact --help token (is_help_option_present, strip_help_options, first_help_option_index).
  • Each of the four dispatch layers (CLIDriver.main, ServiceCommand, ServiceOperation, BasicCommand) routes to its existing create_help_command() with --help stripped. Detecting it up front means a preceding value option cannot consume it.
  • --help is added to _NO_AUTO_PROMPT_ARGS so a help request bypasses auto-prompt.

Behavior

  • The position mirrors the help subcommand. Help resolves at the depth reached when --help appears, and tokens (sub-commands or parameters) after it are ignored, so aws ec2 --help describe-instances renders EC2 service help. This is the same as aws ec2 help describe-instances.
  • Exact token only. Only the literal --help is help. --hel, --he, and --help=x are not; they fall through as unknown options. This avoids colliding with operation parameters with a shared prefix, like --health-check-type.
  • Option values are not treated as commands. aws --region ec2 --help renders top-level help, because ec2 is --region's value.

Known limitation

--help is deliberately absent from the generated global-options synopsis and reference pages. Those are generated from cli.json and pinned by tests/functional/test_globals.py; --help is intentionally not a cli.json option, since that would re-enable prefix matching so --hel resolves again. Users find --help through the error text shown on a bad invocation and each command's own help output.

Testing

  • New functional tests cover --help on every command type, including value and optional-value options before --help, and --help before a command/operation token.
  • New unit tests cover the argparser helpers, exact-token-only detection, value-aware routing, the pre-help-slice parse, and subcommand-vs-help positioning.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Resolve help intent before argument binding so --help renders the same
help as the positional help subcommand on every command surface
(provider, service, operation, custom/nested commands). New argparser
helpers detect and strip the exact --help token; each of the four
dispatch layers routes to its existing create_help_command(). --help
mirrors the positional help token's position semantics, and is added to
_NO_AUTO_PROMPT_ARGS so a help request bypasses auto-prompt. The
positional help subcommand is unchanged.
Functional coverage of --help on every surface, including value and
optional-value options before --help, and --help appearing before a
command or operation token (help resolves at the depth reached, later
tokens ignored).

Unit coverage for the argparser helpers:
- only the exact --help token counts as help
- an option's value is not mistaken for a command when routing to
  top-level help
- parsing the tokens before --help still lets --version and Ctrl-C
  through
- descending into a subcommand is decided by parsing rather than string
  position

Updates the structured-error fixture for the extended HELP_BLURB.
@kdaily kdaily changed the title Kdaily feature help parameter [v2] Add --help parameter for all CLI commands Sep 10, 2026
@kdaily kdaily added the v2 label Sep 10, 2026
@kdaily
kdaily marked this pull request as ready for review September 10, 2026 21:14
@kdaily
kdaily requested a review from a team as a code owner September 10, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant