add storefalse properties for boolean option

This commit is contained in:
Emmanuel Garette 2019-04-03 07:51:26 +02:00 committed by Emmanuel Garette
parent f25df1f1f4
commit 132d57a4c6
2 changed files with 28 additions and 6 deletions

View file

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

View file

@ -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)]
#