diff --git a/test/test_readme.py b/test/test_readme.py index 54ccee0..d551326 100644 --- a/test/test_readme.py +++ b/test/test_readme.py @@ -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, diff --git a/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py b/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py index 6a5beac..fe7557a 100644 --- a/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py +++ b/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py @@ -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)] #