From 504d5d71a4b7de95c004f00d5b96e7030e1cbad0 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Tue, 30 Jul 2019 08:48:46 +0200 Subject: [PATCH] problem with boolean option --- tests/test_readme.py | 13 ++++++------- tiramisu_cmdline_parser/api.py | 11 +++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/test_readme.py b/tests/test_readme.py index 58848ce..b74de2d 100644 --- a/tests/test_readme.py +++ b/tests/test_readme.py @@ -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,13 +290,12 @@ 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 - --str STR string option + -h, --help show this help message and exit + -v, --verbosity increase output verbosity + --str STR string option """ parser = TiramisuCmdlineParser(get_config(json), 'prog.py', display_modified_value=False) f = StringIO() diff --git a/tiramisu_cmdline_parser/api.py b/tiramisu_cmdline_parser/api.py index 4bbe00c..ae8879b 100644 --- a/tiramisu_cmdline_parser/api.py +++ b/tiramisu_cmdline_parser/api.py @@ -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,