Skip to content

Commit 09f836e

Browse files
Fix #315 Change the _KeywordOnlyArguments filtering condition (#316)
* Change the _KeywordOnlyArguments filtering condition * Add test case for usage output of function with mixed defaults Signed-off-by: Xavier Figueroa <[email protected]>
1 parent 21ae57c commit 09f836e

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

fire/helptext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def _GetCallableUsageItems(spec, metadata):
700700

701701
def _KeywordOnlyArguments(spec, required=True):
702702
return (flag for flag in spec.kwonlyargs
703-
if required == (flag in spec.kwonlydefaults))
703+
if required != (flag in spec.kwonlydefaults))
704704

705705

706706
def _GetCallableAvailabilityLines(spec):

fire/helptext_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,20 @@ def testUsageOutputFunctionWithDocstring(self):
497497
textwrap.dedent(expected_output).lstrip('\n'),
498498
usage_output)
499499

500+
def testUsageOutputFunctionMixedDefaults(self):
501+
component = tc.MixedDefaults().identity2
502+
t = trace.FireTrace(component, name='FunctionMixedDefaults')
503+
usage_output = helptext.UsageText(component, trace=t, verbose=False)
504+
expected_output = """
505+
Usage: FunctionMixedDefaults <flags>
506+
optional flags: --beta
507+
required flags: --alpha
508+
509+
For detailed information on this command, run:
510+
FunctionMixedDefaults --help"""
511+
expected_output = textwrap.dedent(expected_output).lstrip('\n')
512+
self.assertEqual(expected_output, usage_output)
513+
500514
def testUsageOutputCallable(self):
501515
# This is both a group and a command.
502516
component = tc.CallableWithKeywordArgument()

fire/test_components.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ def sum(self, alpha=0, beta=0):
133133
def identity(self, alpha, beta='0'):
134134
return alpha, beta
135135

136+
def identity2(self, *, alpha, beta='0'):
137+
return alpha, beta
138+
136139

137140
class SimilarArgNames(object):
138141

0 commit comments

Comments
 (0)