Force equal sign for long options to allow variable option positions.

This commit is contained in:
Bastian Kleineidam 2010-03-06 13:48:50 +01:00
parent 12d0340af8
commit 6decebe6f7
2 changed files with 16 additions and 18 deletions

View File

@ -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

View File

@ -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"})