From 6decebe6f7997344af953b9ee38fe1d5f78775aa Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 6 Mar 2010 13:48:50 +0100 Subject: [PATCH] Force equal sign for long options to allow variable option positions. --- patoolib/baker.py | 19 +++++-------------- tests/test_baker.py | 15 +++++++++++---- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/patoolib/baker.py b/patoolib/baker.py index 2994986..19f0fa4 100644 --- a/patoolib/baker.py +++ b/patoolib/baker.py @@ -373,7 +373,8 @@ class Baker(object): except TypeError: pass else: - # The argument was not specified with an equals sign... + # The argument was not specified with a value, assuming + # this is a flag name = arg[2:] default = keywords.get(name) @@ -383,19 +384,9 @@ class Baker(object): # opposite of the default". value = not default else: - # The next item in the argument list is the value, i.e. - # --keyword value - if not argv or argv[0].startswith("-"): - # Oops, there isn't a value available... just use - # True, assuming this is a flag. - value = True - else: - value = argv.pop(0) - - try: - value = totype(value, default) - except TypeError: - pass + # Option is specified via the params value, assuming + # a True value + value = True # Store this option kwargs[name] = value diff --git a/tests/test_baker.py b/tests/test_baker.py index 39395c6..db05bec 100644 --- a/tests/test_baker.py +++ b/tests/test_baker.py @@ -35,10 +35,17 @@ class TestBaker (unittest.TestCase): def test_func_kwargs (self): @baker.command - def func(arg1, *args, **kwargs): - return arg1 - res = baker.run(argv=[__file__, 'func', 'argvalue1']) - self.assertEqual(res, 'argvalue1') + def func(arg1, arg2, *args, **kwargs): + return arg1, arg2, kwargs['verbose'] + res = baker.run(argv=[__file__, 'func', 'argvalue1', 'argvalue2', '--verbose']) + self.assertEqual(res, ('argvalue1', 'argvalue2', True)) + + def test_func_kwargs_revorder (self): + @baker.command + def func(arg1, arg2, *args, **kwargs): + return arg1, arg2, kwargs['verbose'] + res = baker.run(argv=[__file__, 'func', 'argvalue1', '--verbose', 'argvalue2']) + self.assertEqual(res, ('argvalue1', 'argvalue2', True)) def test_func_kwargs_params (self): @baker.command(params={"verbose": "Be verbose"})