Skip to content

Commit b1dc471

Browse files
committed
Fix incorrect --help output
This issue began in version 2.1.0. See 2.0.63...2.1.0#diff-45cb40c448cb3c90162a08a8d5c86559afb843a7678339500c3fb15933b5dcceR89. A parsing layer (FirstPassGlobalArgParser) was added specifically to parse global arguments. It is a subclass of argparse and by default it injects a _HelpAction unless `add_help=False` is provided. It also suppresses its help output, so the the --help action consumed the --help argument. This led to the default arparse output and exiting with rc 0. The global parsing logic was also moved into `create_clidriver`. This means that all test logic using clidriver.main is no longer running arguments through the full argument parsing gauntlet that is being run in real usage. So the tests designed to target --help, --profile, and --debug are not going through the code path that actually parses them. Further review is needed to see which tests need to change and how the parsing behavior should be updated. modified: awscli/argparser.py # modified: tests/unit/test_clidriver.py #
1 parent 72fe461 commit b1dc471

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "argument parsing",
4+
"description": "Fixes issue reported in `#303 <https://github.com/aws/aws-cli/issues/303>`__ involving -h/--help output"
5+
}

awscli/argparser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def _non_required_arg_table(self, argument_table):
277277

278278
class FirstPassGlobalArgParser(CLIArgParser):
279279
def __init__(self, *args, **kwargs):
280+
kwargs['add_help'] = False
280281
super().__init__(*args, **kwargs)
281282
self._build()
282283

tests/unit/test_clidriver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ def test_help_blurb_in_operation_error_message(self):
749749
self.assertIn(HELP_BLURB, self.stderr.getvalue())
750750

751751
def test_help_blurb_in_unknown_argument_error_message(self):
752-
rc = self.driver.main(['s3api', 'list-objects', '--help'])
752+
args = ['s3api', 'list-objects', '--help']
753+
driver = create_clidriver(args)
754+
rc = driver.main(args)
753755
self.assertEqual(rc, 252)
754756
self.assertIn(HELP_BLURB, self.stderr.getvalue())
755757

0 commit comments

Comments
 (0)