diff --git a/test/test_readme.py b/test/test_readme.py index b90f022..6e86c04 100644 --- a/test/test_readme.py +++ b/test/test_readme.py @@ -109,7 +109,7 @@ root: assert f.getvalue() == output -def test_readme_help_modif(): +def test_readme_help_modif_positional(): output = """usage: prog.py str [-h] [-v] --str STR optional arguments: @@ -129,6 +129,44 @@ optional arguments: assert f.getvalue() == output +def test_readme_help_modif(): + output = """usage: prog.py str --str toto [-h] [-v] + +optional arguments: + -h, --help show this help message and exit + -v, --verbosity increase output verbosity +""" + parser = TiramisuCmdlineParser(get_config(), 'prog.py') + f = StringIO() + with redirect_stdout(f): + try: + parser.parse_args(['str', '--str', 'toto', '--help']) + except SystemExit as err: + assert str(err) == "0" + else: + raise Exception('must raises') + assert f.getvalue() == output + + +def test_readme_help_modif_short(): + output = """usage: prog.py str --verbosity [-h] --str STR + +optional arguments: + -h, --help show this help message and exit + --str STR string option +""" + parser = TiramisuCmdlineParser(get_config(), 'prog.py') + f = StringIO() + with redirect_stdout(f): + try: + parser.parse_args(['str', '-v', '--help']) + except SystemExit as err: + assert str(err) == "0" + else: + raise Exception('must raises') + assert f.getvalue() == output + + def test_readme_positional_mandatory(): output = """usage: prog.py [-h] [-v] {str,list,int,none} prog.py: error: the following arguments are required: cmd diff --git a/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py b/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py index 30e7c6c..95c0f0b 100644 --- a/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py +++ b/tiramisu_cmdline_parser/tiramisu_cmdline_parser.py @@ -180,10 +180,15 @@ class TiramisuCmdlineParser(ArgumentParser): properties = obj.property.get() kwargs = {'help': option.doc().replace('%', '%%')} if option.issymlinkoption(): - actions[option.name(follow_symlink=True)][0].insert(0, self._gen_argument(option.name(), properties)) + symlink_name = option.name(follow_symlink=True) + if symlink_name in actions: + actions[symlink_name][0].insert(0, self._gen_argument(option.name(), properties)) continue if _forhelp and not obj.owner.isdefault() and obj.value.get(): - self.prog += ' {}'.format(obj.value.get()) + if 'positional' not in properties: + self.prog += ' {}'.format(self._gen_argument(name, properties)) + if option.type() != 'boolean': + self.prog += ' {}'.format(obj.value.get()) else: if 'positional' in properties: if not 'mandatory' in properties: