Skip to content

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

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

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
Comment thread awscli/clidriver.py
# append the ``help`` positional argument, so a trailing command is
# ignored.
head = self._tokens_before_help(args)
return head + ['help']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we avoid converting the help request into a positional help token here? The parse fails because --query has no value, so this rewrites argv to ... --query help, which strips the help intent and lets the command run. Worried about destructive operations like aws s3api delete-object --bucket b --key k --query --help when the intent is --help

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth a regression test on a mutating operation specifically

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. Supplying --help should never behave as supplying help as a value to another parameter.

Comment thread awscli/argparser.py

def first_help_option_index(args):
"""Return the index of the first ``--help`` token, or ``None`` if absent."""
for index, arg in enumerate(args):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Help detection should stop at the -- end-of-options marker. aws configure set test.key -- --help normally treats --help as the positional value, but this interprets it as a help request and renders command help instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed, it should behave as other parameters in this aspect. I'll publish a revision

Comment thread awscli/clidriver.py
# that exceptions can be raised, which should have the same
# general exception handling logic as calling into the
# command table. This is why it's in the try/except clause.
parsed_args, remaining = parser.parse_known_args(args)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could help get consumed as the preceding option’s value here? For example:
aws ec2 terminate-instances --instance-ids i-abc123 --query --help

Currently on v2 this fails because --query has no value. With this change it effectively becomes --query help and calls TerminateInstances.

My read is help can be a query value, but --help is an explicit option.
Could we preserve that distinction instead of reinserting it as a normal

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree. It should behave more like other parameters. I'll revise.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this would mean that we need to enter help directly (calling the help command)?

@aemous aemous self-assigned this Sep 16, 2026
@aemous

aemous commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

I am taking over ownership of implementing this feature.

Closing in favor of #10657.

@aemous aemous closed this Sep 16, 2026
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.

3 participants