help with modified argument

This commit is contained in:
Emmanuel Garette 2019-04-02 19:01:17 +02:00
parent 3ac9031411
commit 075de80f73
2 changed files with 46 additions and 3 deletions

View File

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

View File

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