problem with boolean option

This commit is contained in:
Emmanuel Garette 2019-07-30 08:48:46 +02:00
parent e2c4e3381a
commit 504d5d71a4
2 changed files with 13 additions and 11 deletions

View File

@ -250,7 +250,7 @@ def test_readme_help_modif_short_remove(json):
optional arguments:
-h, --help show this help message and exit
-nv, --no-verbosity
-nv, --no-verbosity increase output verbosity
--str STR string option
"""
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)
@ -265,7 +265,7 @@ optional arguments:
assert f.getvalue() == output
def test_readme_help_modif_short_no(json):
def test_readme_help_modif_short_no1(json):
output = """usage: prog.py "str" -v [-h] [-v] [-nv] --str STR {str,list,int,none}
positional arguments:
@ -290,12 +290,11 @@ optional arguments:
def test_readme_help_modif_short_no_remove(json):
# FIXME -v -nv ?? c'est -nv qui est set
output = """usage: prog.py "str" -v [-h] [-nv] --str STR
output = """usage: prog.py "str" -v [-h] [-v] --str STR
optional arguments:
-h, --help show this help message and exit
-nv, --no-verbosity
-v, --verbosity increase output verbosity
--str STR string option
"""
parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False)

View File

@ -147,13 +147,15 @@ class _BuildKwargs:
cmdlineparser: 'TiramisuCmdlineParser',
properties: List[str],
force_no: bool,
force_del: bool) -> None:
force_del: bool,
display_modified_value: bool,
not_display: bool) -> None:
self.kwargs = {}
self.cmdlineparser = cmdlineparser
self.properties = properties
self.force_no = force_no
self.force_del = force_del
if not self.force_no and not self.force_del:
if (not self.force_no or (not_display and not display_modified_value)) and not self.force_del:
description = option.doc()
if not description:
description = description.replace('%', '%%')
@ -404,8 +406,9 @@ class TiramisuCmdlineParser(ArgumentParser):
properties = obj.option.properties()
else:
properties = obj.property.get()
kwargs = _BuildKwargs(name, option, self, properties, force_no, force_del)
if not option.isfollower() and _forhelp and not obj.owner.isdefault() and value is not None and not force_no:
not_display = not option.isfollower() and not obj.owner.isdefault() and value is not None
kwargs = _BuildKwargs(name, option, self, properties, force_no, force_del, self.display_modified_value, not_display)
if _forhelp and not_display and ((value is not False and not force_no) or (value is False and force_no)):
options_is_not_default[option.name()] = {'properties': properties,
'type': option.type(),
'name': name,