Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a491847

Browse files
authored
Show default values for kwonly arguments in help text (#414)
Fixes #410 * Shows default values for kwonly arguments in help text * Adds test verifying that default values are shown for kwonly args
1 parent c4bd14b commit a491847

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

fire/helptext.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ def _GetArgDefault(flag, spec):
524524
for arg, default in zip(args_with_defaults, spec.defaults):
525525
if arg == flag:
526526
return repr(default)
527+
if flag in spec.kwonlydefaults:
528+
return repr(spec.kwonlydefaults[flag])
527529
return ''
528530

529531

fire/helptext_test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,18 @@ def testHelpTextKeywordOnlyArgumentsWithoutDefault(self):
296296
self.assertIn('NAME\n double', output)
297297
self.assertIn('FLAGS\n --count=COUNT (required)', output)
298298

299+
@testutils.skipIf(
300+
six.PY2,
301+
'Python 2 does not support required name-only arguments.')
302+
def testHelpTextFunctionMixedDefaults(self):
303+
component = tc.py3.HelpTextComponent().identity
304+
t = trace.FireTrace(component, name='FunctionMixedDefaults')
305+
output = helptext.HelpText(component, trace=t)
306+
self.assertIn('NAME\n FunctionMixedDefaults', output)
307+
self.assertIn('FunctionMixedDefaults <flags>', output)
308+
self.assertIn('--alpha=ALPHA (required)', output)
309+
self.assertIn('--beta=BETA\n Default: \'0\'', output)
310+
299311
def testHelpScreen(self):
300312
component = tc.ClassWithDocstring()
301313
t = trace.FireTrace(component, name='ClassWithDocstring')

0 commit comments

Comments
 (0)