help.make_usage_str(): improve usage indentation
This commit is contained in:
parent
db8b769faa
commit
165d65d4ed
1 changed files with 9 additions and 11 deletions
|
|
@ -77,21 +77,19 @@ def gen_arg_tuple(cfg, func, text):
|
||||||
for arg in func.__code__.co_varnames:
|
for arg in func.__code__.co_varnames:
|
||||||
yield d[arg] if arg in d else text
|
yield d[arg] if arg in d else text
|
||||||
|
|
||||||
def make_usage_str(cfg, caller):
|
def make_usage_str(cfg, *, caller):
|
||||||
indent, col1_w = {
|
|
||||||
'help': (2, len(gc.prog_name) + 1),
|
|
||||||
'user': (0, len('USAGE:')),
|
|
||||||
}[caller]
|
|
||||||
def gen():
|
def gen():
|
||||||
ulbl = 'USAGE:'
|
single_line = isinstance(cfg._usage_data, str)
|
||||||
for line in [cfg._usage_data.strip()] if isinstance(cfg._usage_data, str) else cfg._usage_data:
|
ulbl = 'USAGE:' + (' ' if single_line else join_str)
|
||||||
yield '{a:{w}} {b} {c}'.format(
|
for line in [cfg._usage_data.strip()] if single_line else cfg._usage_data:
|
||||||
|
yield '{a}{b} {c}'.format(
|
||||||
a = ulbl,
|
a = ulbl,
|
||||||
b = gc.prog_name,
|
b = gc.prog_name,
|
||||||
c = cfg._usage_code(*gen_arg_tuple(cfg, cfg._usage_code, line)) if cfg._usage_code else line,
|
c = cfg._usage_code(*gen_arg_tuple(cfg, cfg._usage_code, line))
|
||||||
w = col1_w)
|
if cfg._usage_code else line)
|
||||||
ulbl = ''
|
ulbl = ''
|
||||||
return ('\n' + (' ' * indent)).join(gen())
|
join_str = {'help': '\n ', 'user': '\n '}[caller]
|
||||||
|
return join_str.join(gen())
|
||||||
|
|
||||||
def usage(cfg):
|
def usage(cfg):
|
||||||
print(make_usage_str(cfg, caller='user'))
|
print(make_usage_str(cfg, caller='user'))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue