help with modified argument
This commit is contained in:
parent
89ec6309b1
commit
b5c50071b5
2 changed files with 46 additions and 3 deletions
|
@ -109,7 +109,7 @@ root:
|
||||||
assert f.getvalue() == output
|
assert f.getvalue() == output
|
||||||
|
|
||||||
|
|
||||||
def test_readme_help_modif():
|
def test_readme_help_modif_positional():
|
||||||
output = """usage: prog.py str [-h] [-v] --str STR
|
output = """usage: prog.py str [-h] [-v] --str STR
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
|
@ -129,6 +129,44 @@ optional arguments:
|
||||||
assert f.getvalue() == output
|
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():
|
def test_readme_positional_mandatory():
|
||||||
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
output = """usage: prog.py [-h] [-v] {str,list,int,none}
|
||||||
prog.py: error: the following arguments are required: cmd
|
prog.py: error: the following arguments are required: cmd
|
||||||
|
|
|
@ -180,9 +180,14 @@ class TiramisuCmdlineParser(ArgumentParser):
|
||||||
properties = obj.property.get()
|
properties = obj.property.get()
|
||||||
kwargs = {'help': option.doc().replace('%', '%%')}
|
kwargs = {'help': option.doc().replace('%', '%%')}
|
||||||
if option.issymlinkoption():
|
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
|
continue
|
||||||
if _forhelp and not obj.owner.isdefault() and obj.value.get():
|
if _forhelp and not obj.owner.isdefault() and 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())
|
self.prog += ' {}'.format(obj.value.get())
|
||||||
else:
|
else:
|
||||||
if 'positional' in properties:
|
if 'positional' in properties:
|
||||||
|
|
Loading…
Reference in a new issue