From 4d93057347ec5865069047b26092e20b7fedad7b Mon Sep 17 00:00:00 2001 From: James Saryerwinnie Date: Wed, 20 Aug 2014 09:28:16 -0700 Subject: [PATCH] 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)