From 0e69709efae1812712d0f0e3cb9e8ada6b963f8d Mon Sep 17 00:00:00 2001 From: emre Date: Thu, 18 Jul 2013 10:54:53 +0300 Subject: [PATCH 1/2] - Added support for multiple values for a single positional argument. def bar(c=[]): print c komandr.command(bar) ./foo.py --c=arg1 --c=arg2 ['arg1', 'arg2', ] - Added related unit tests. --- komandr.py | 4 ++++ tests.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/komandr.py b/komandr.py index 96f505b..d168a80 100644 --- a/komandr.py +++ b/komandr.py @@ -82,6 +82,10 @@ def _generate_command(self, func, name=None, **kwargs): args = list(args) is_positional = isinstance(v, self._POSITIONAL) options = [arg for arg in args if arg.startswith('-')] + if isinstance(v, list): + kwargs.update({ + 'action': 'append', + }) if is_positional: if options: args = options diff --git a/tests.py b/tests.py index 59687c0..e02d6e4 100644 --- a/tests.py +++ b/tests.py @@ -12,6 +12,14 @@ def foo(bar, baz=None): self.assertEqual(('1', '2'), komandr.execute(['foo', '1', '--baz', '2'])) + def testMultipleValuesForASingleArgument(self): + + def bar(c=[]): + return c + komandr.command(bar) + + self.assertEqual(['blue', 'red',], komandr.execute(['bar', '--c', 'blue', '--c', 'red'])) + if __name__ == '__main__': unittest.main() From 539ee586a9ff25fa0e5343f55f96270abc231374 Mon Sep 17 00:00:00 2001 From: emre Date: Thu, 18 Jul 2013 10:57:42 +0300 Subject: [PATCH 2/2] pep8 fix --- tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.py b/tests.py index e02d6e4..68b6629 100644 --- a/tests.py +++ b/tests.py @@ -18,7 +18,7 @@ def bar(c=[]): return c komandr.command(bar) - self.assertEqual(['blue', 'red',], komandr.execute(['bar', '--c', 'blue', '--c', 'red'])) + self.assertEqual(['blue', 'red', ], komandr.execute(['bar', '--c', 'blue', '--c', 'red'])) if __name__ == '__main__':