From 4d93057347ec5865069047b26092e20b7fedad7b Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Wed, 20 Aug 2014 09:28:16 -0700 Subject: [PATCH 1/2] Error out for remaining args in custom commands --- awscli/clidriver.py | 1 + awscli/customizations/commands.py | 2 ++ tests/unit/customizations/s3/test_ls_command.py | 8 +++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/awscli/clidriver.py b/awscli/clidriver.py index 57052006c603..996869098f28 100644 --- a/awscli/clidriver.py +++ b/awscli/clidriver.py @@ -194,6 +194,7 @@ def main(self, args=None): self._handle_top_level_args(parsed_args) return command_table[parsed_args.command](remaining, parsed_args) except UnknownArgumentError as e: + sys.stderr.write("\n") sys.stderr.write(str(e) + '\n') return 255 except NoRegionError as e: diff --git a/awscli/customizations/commands.py b/awscli/customizations/commands.py index cb67c6adafa7..0700b7cfe1d2 100644 --- a/awscli/customizations/commands.py +++ b/awscli/customizations/commands.py @@ -176,6 +176,8 @@ def __call__(self, args, parsed_globals): elif getattr(parsed_args, 'subcommand', None) is None: # No subcommand was specified so call the main # function for this top level command. + if remaining: + raise ValueError("Unknown options: %s" % ','.join(remaining)) return self._run_main(parsed_args, parsed_globals) else: return subcommand_table[parsed_args.subcommand](remaining, diff --git a/tests/unit/customizations/s3/test_ls_command.py b/tests/unit/customizations/s3/test_ls_command.py index 08551dd6b975..b8b5b01fc6fc 100644 --- a/tests/unit/customizations/s3/test_ls_command.py +++ b/tests/unit/customizations/s3/test_ls_command.py @@ -14,6 +14,7 @@ from awscli.testutils import BaseAWSCommandParamsTest from dateutil import parser, tz + class TestLSCommand(BaseAWSCommandParamsTest): def test_operations_used_in_recursive_list(self): @@ -34,6 +35,7 @@ def test_operations_used_in_recursive_list(self): self.assertEqual( stdout, '%s 100 foo/bar.txt\n'%time_local.strftime('%Y-%m-%d %H:%M:%S')) - -if __name__ == "__main__": - unittest.main() + def test_errors_out_with_extra_arguments(self): + stderr = self.run_cmd('s3 ls --extra-argument-foo', expected_rc=255)[1] + self.assertIn('Unknown options', stderr) + self.assertIn('--extra-argument-foo', stderr) From a48e0f595a650a6421174af8219d9166d0938444 Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Wed, 20 Aug 2014 13:43:07 -0700 Subject: [PATCH 2/2] Add entry to changelog --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ac223359cad9..c435dfcd540d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -13,6 +13,10 @@ Next Release (TBD) * feature:Parameter Shorthand: Added support for ``structure(list-scalar, scalar)`` parameter shorthand. (`issue 882 `__) +* bugfix:``aws s3``: Fix bug when unknown options were + passed to ``aws s3`` commands + (`issue 886 `__) + 1.4.2 =====