Force equal sign for long options to allow variable option positions.
This commit is contained in:
parent
12d0340af8
commit
6decebe6f7
|
@ -373,7 +373,8 @@ class Baker(object):
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
else:
|
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:]
|
name = arg[2:]
|
||||||
default = keywords.get(name)
|
default = keywords.get(name)
|
||||||
|
|
||||||
|
@ -383,19 +384,9 @@ class Baker(object):
|
||||||
# opposite of the default".
|
# opposite of the default".
|
||||||
value = not default
|
value = not default
|
||||||
else:
|
else:
|
||||||
# The next item in the argument list is the value, i.e.
|
# Option is specified via the params value, assuming
|
||||||
# --keyword value
|
# a True 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
|
value = True
|
||||||
else:
|
|
||||||
value = argv.pop(0)
|
|
||||||
|
|
||||||
try:
|
|
||||||
value = totype(value, default)
|
|
||||||
except TypeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Store this option
|
# Store this option
|
||||||
kwargs[name] = value
|
kwargs[name] = value
|
||||||
|
|
|
@ -35,10 +35,17 @@ class TestBaker (unittest.TestCase):
|
||||||
|
|
||||||
def test_func_kwargs (self):
|
def test_func_kwargs (self):
|
||||||
@baker.command
|
@baker.command
|
||||||
def func(arg1, *args, **kwargs):
|
def func(arg1, arg2, *args, **kwargs):
|
||||||
return arg1
|
return arg1, arg2, kwargs['verbose']
|
||||||
res = baker.run(argv=[__file__, 'func', 'argvalue1'])
|
res = baker.run(argv=[__file__, 'func', 'argvalue1', 'argvalue2', '--verbose'])
|
||||||
self.assertEqual(res, 'argvalue1')
|
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):
|
def test_func_kwargs_params (self):
|
||||||
@baker.command(params={"verbose": "Be verbose"})
|
@baker.command(params={"verbose": "Be verbose"})
|
||||||
|
|
Loading…
Reference in New Issue