Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to verify no options are being shadowed by top level options #1068

Merged
merged 2 commits into from
Dec 19, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Next Release (TBD)
* bugfix:``aws ec2 run-instances``: Allow binary files to be passed to
``--user-data``
(`botocore issue 416 <https://github.com/boto/botocore/pull/416>`_)
* bugfix:``aws cloudsearchdomain suggest``: Add ``--suggest-query``
option to fix the argument being shadowed by the top level
``--query`` option.
(`issue 1068 <https://github.com/aws/aws-cli/pull/1068>`__)


1.6.10
Expand Down
1 change: 1 addition & 0 deletions awscli/customizations/argrename.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'emr.*.job-flow-ids': 'cluster-ids',
'emr.*.job-flow-id': 'cluster-id',
'cloudsearchdomain.search.query': 'search-query',
'cloudsearchdomain.suggest.query': 'suggest-query',
'sns.subscribe.endpoint': 'notification-endpoint',
'deploy.*.s-3-location': 's3-location',
'deploy.*.ec-2-tag-filters': 'ec2-tag-filters',
Expand Down
43 changes: 43 additions & 0 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,49 @@

import botocore.session
from awscli.testutils import unittest, aws
from awscli.clidriver import create_clidriver


def test_no_shadowed_builtins():
"""Verify no command params are shadowed by the built in param.

The CLI parses all command line options into a single namespace.
This means that option names must be unique and cannot conflict
with the top level params.

For example, there's a top level param ``--version``. If an
operation for a service also provides a ``--version`` option,
it can never be called because we'll assume the user meant
the top level ``--version`` param.

In order to ensure this doesn't happen, this test will go
through every command table and ensure we're not shadowing
any builtins.

Also, rather than being a test generator, we're going to just
aggregate all the failures in one pass and surface them as
a single test failure.

"""
driver = create_clidriver()
help_command = driver.create_help_command()
top_level_params = set(driver.create_help_command().arg_table)
errors = []
for command_name, command_obj in help_command.command_table.items():
sub_help = command_obj.create_help_command()
if hasattr(sub_help, 'command_table'):
for sub_name, sub_command in sub_help.command_table.items():
op_help = sub_command.create_help_command()
arg_table = op_help.arg_table
for arg_name in arg_table:
if arg_name in top_level_params:
# Then we're shadowing a built in argument.
errors.append(
'Shadowing a top level option: %s.%s.%s' % (
command_name, sub_name, arg_name))

if errors:
raise AssertionError('\n' + '\n'.join(errors))


class TestBasicCommandFunctionality(unittest.TestCase):
Expand Down