Commit eeca0743 authored by Emmanuel Garette's avatar Emmanuel Garette

add storefalse properties for boolean option

parent 266cef22
......@@ -7,7 +7,7 @@ from tiramisu import IntOption, StrOption, BoolOption, ChoiceOption, \
SymLinkOption, OptionDescription, Config
def get_config(has_tree=False):
def get_config(has_tree=False, default_verbosity=False):
choiceoption = ChoiceOption('cmd',
'choice the sub argument',
('str', 'list', 'int', 'none'),
......@@ -15,7 +15,7 @@ def get_config(has_tree=False):
'positional'))
booloption = BoolOption('verbosity',
'increase output verbosity',
default=False)
default=default_verbosity)
short_booloption = SymLinkOption('v', booloption)
str_ = StrOption('str',
'string option',
......@@ -412,6 +412,28 @@ def test_readme_int_verbosity_short():
assert config.value.dict() == output
def test_readme_int_verbosity_short_store_false():
output = {'cmd': 'int',
'int': 3,
'verbosity': None,
'v': True}
config = get_config(default_verbosity=None)
config.option('verbosity').property.add('storefalse')
parser = TiramisuCmdlineParser(config, 'prog.py')
parser.parse_args(['int', '--int', '3', '-v'])
output = {'cmd': 'int',
'int': 3,
'verbosity': False,
'v': False}
assert config.value.dict() == output
parser.parse_args(['int', '--int', '3', '-nv'])
output = {'cmd': 'int',
'int': 3,
'verbosity': True,
'v': True}
assert config.value.dict() == output
def test_readme_int_verbosity_short_no():
output = {'cmd': 'int',
'int': 3,
......
......@@ -221,12 +221,12 @@ class TiramisuCmdlineParser(ArgumentParser):
if _forhelp and 'mandatory' in properties:
kwargs['required'] = True
if option.type() == 'boolean':
if obj.value.get() is False:
action = 'store_true'
no_action = 'store_false'
else:
if 'storefalse' in properties:
action = 'store_false'
no_action = 'store_true'
else:
action = 'store_true'
no_action = 'store_false'
kwargs['action'] = action
args = [self._gen_argument(name, 'longargument' in properties)]
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment