Skip to content

[v2] Add --help alias for rendering help docs - #10657

Open
aemous wants to merge 11 commits into
v2from
v2-help-flag
Open

aemous wants to merge 11 commits into
v2from
v2-help-flag

Conversation

@aemous

@aemous aemous commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

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.
  • Add --help as a global option to the AWS CLI API Reference and the help docs.

Description of tests:

  • New tests covering --help on every command type, including value and optional-value options before --help, and --help before a command/operation token.

The following commands were tested, either manually or in new automated tests, or both (NOTE: generated by AI and manually verified by me (human)):

Scenario Example command help behavior --help behavior
Top-level aws help / aws --help Shows provider help Shows provider help
Service aws ec2 help / aws ec2 --help Shows ec2 help Shows ec2 help
Operation aws ec2 run-instances help / aws ec2 run-instances --help Shows run-instances help Shows run-instances help
Custom service aws s3 help / aws s3 --help Shows s3 help Shows s3 help
Custom operation aws s3 ls help / aws s3 ls --help Shows ls help Shows ls help
Abbreviation aws --hel N/A Shows provider help
Before modeled operation aws s3api --help put-object / aws s3api help put-object Shows s3api help Shows put-object help
Before modeled service aws --help s3api put-object / aws help s3api put-object Errors "invalid choice s3api" Shows put-object help
Global flag missing value aws s3api delete-object --query help / --query --help help consumed as --query value, returns null Shows delete-object help
Op-level flag with choices aws s3 cp --acl help / --acl --help Errors "invalid choice 'help'" Shows cp help
Op-level flag with free value aws s3 cp --expected-size help / --expected-size --help help consumed as value, errors missing paths Shows cp help
Positional args present aws s3 cp localfile s3://bucket/key help / --help help consumed as positional, errors "Unknown options" Shows cp help
Invalid top-level command aws fake-service help / aws fake-service --help Errors "invalid choice" Errors "invalid choice"
Invalid service operation aws s3api fake-command help / aws s3api fake-command --help Errors "invalid choice" Errors "invalid choice"
Invalid custom command operation aws s3 fake-command help / aws s3 fake-command --help Errors "invalid choice" Errors "invalid choice"

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

Comment thread awscli/argparser.py


class _HelpFlagResolver(argparse.ArgumentParser):
"""Minimal parser that detects --help (and abbreviations like --hel, --he).

@kdaily kdaily Sep 17, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Allowing abbreviations means that any existing top level parameter that turns into a CLI flag and shares a prefix with help is now superseded by the help system. For example, aws shield associate-health-check has a parameter --health-check-arn Previously, --he arn:123:abc would pass the value arn:123:abc to the HealthCheckArn property:

$ aws shield associate-health-check --he arn:123:abc --protection-id 123456789123456789123456789123456789

However, with this change, this now opens the help. While this example may be mitigated by determining that a value follows the flag, there's no limitation that a top level parameter with a shared prefix to help has to.

Comment thread awscli/clidriver.py
current_cmd([arg, 'help'], None)
else:
parser = self.create_parser(command_table)
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.

aws --region us-west-2 ec2 describe-instances --help prints nothing and exits with 0.
It looks like --region is skipped but not us-west-2 in the loop above which is skipping any token starting with a dash but not its value

Comment thread awscli/clidriver.py
# Bare word that isn't a known command — let the
# real parser produce the "invalid choice" error.
if current_cmd is not None:
current_cmd([arg, 'help'], None)

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.

Similarly to my other comment --help doesn't reach help here the way the positional does aws ec2 --region us-east-1 help renders ec2 help and aws ec2 --region us-east-1 --help gives argument operation: Found invalid choice 'us-east-1', because --region is skipped but not its value

Comment thread awscli/clidriver.py
parser.parse_known_args(args)
return
if current_cmd is None:
return self.create_help_command()([], None)

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.

Does this work for aliases? aws my-ec2 --help prints nothing and exits 0 for me

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.

Looks like BaseAliasCommand inherits the base create_help_command() from commands.py, which returns None

Comment thread awscli/clidriver.py
return
if current_cmd is None:
return self.create_help_command()([], None)
help_cmd = current_cmd.create_help_command()

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.

aws help --help

aws: [ERROR]: 'ProviderHelpCommand' object has no attribute 'create_help_command'

Every other double-help collapses to one rendering (aws ec2 help --help, aws ec2 --help help, aws ec2 describe-instances help --help) all render the same page as the plain help form, whcih makes me expect was help --help will print aws help, which is what it does today

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