Skip to content

Commit

Permalink
Show default values for kwonly arguments in help text (#414)
Browse files Browse the repository at this point in the history
Fixes #410

* Shows default values for kwonly arguments in help text
* Adds test verifying that default values are shown for kwonly args
  • Loading branch information
dbieber authored Nov 28, 2022
1 parent c4bd14b commit a491847
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fire/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@ def _GetArgDefault(flag, spec):
for arg, default in zip(args_with_defaults, spec.defaults):
if arg == flag:
return repr(default)
if flag in spec.kwonlydefaults:
return repr(spec.kwonlydefaults[flag])
return ''


Expand Down
12 changes: 12 additions & 0 deletions fire/helptext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ def testHelpTextKeywordOnlyArgumentsWithoutDefault(self):
self.assertIn('NAME\n double', output)
self.assertIn('FLAGS\n --count=COUNT (required)', output)

@testutils.skipIf(
six.PY2,
'Python 2 does not support required name-only arguments.')
def testHelpTextFunctionMixedDefaults(self):
component = tc.py3.HelpTextComponent().identity
t = trace.FireTrace(component, name='FunctionMixedDefaults')
output = helptext.HelpText(component, trace=t)
self.assertIn('NAME\n FunctionMixedDefaults', output)
self.assertIn('FunctionMixedDefaults <flags>', output)
self.assertIn('--alpha=ALPHA (required)', output)
self.assertIn('--beta=BETA\n Default: \'0\'', output)

def testHelpScreen(self):
component = tc.ClassWithDocstring()
t = trace.FireTrace(component, name='ClassWithDocstring')
Expand Down

0 comments on commit a491847

Please sign in to comment.