diff --git a/fire/core.py b/fire/core.py index 8e23e76b..632b212e 100644 --- a/fire/core.py +++ b/fire/core.py @@ -935,6 +935,9 @@ def _ParseKeywordArgs(args, fn_spec): remaining_kwargs.append(args[index + 1]) else: # not _IsFlag(argument) remaining_args.append(argument) + # Flags after a positional token belong to later commands in a chain. + remaining_args.extend(args[index + 1:]) + break return kwargs, remaining_kwargs, remaining_args diff --git a/fire/fire_test.py b/fire/fire_test.py index 99b4a7c6..9c0f6ec9 100644 --- a/fire/fire_test.py +++ b/fire/fire_test.py @@ -712,6 +712,27 @@ def testHelpKwargsDecorator(self): with self.assertRaisesFireExit(0): fire.Fire(tc.decorated_method, command=['--help']) + def testChainedKwargsWithSameParameterName(self): + class ChainKwargFoo: + def __init__(self): + self.log = [] + + def bar(self, param=0): + self.log.append(('bar', param)) + return self + + def baz(self, param=0): + self.log.append(('baz', param)) + return self + + def end(self): + return self.log + + obj = ChainKwargFoo() + result = fire.Fire( + obj, command=['bar', '--param=3', 'baz', '--param=5', 'end']) + self.assertEqual(result, [('bar', 3), ('baz', 5)]) + def testFireAsyncio(self): self.assertEqual(fire.Fire(tc.py3.WithAsyncio, command=['double', '--count', '10']), 20)