DRYer
This commit is contained in:
parent
c92ca01ea6
commit
44cca80a0c
1 changed files with 8 additions and 8 deletions
16
kitty/cli.py
16
kitty/cli.py
|
|
@ -380,6 +380,12 @@ def get_defaults_from_seq(seq: OptionSpecSeq) -> dict[str, Any]:
|
|||
appname=appname, url=website_url())
|
||||
|
||||
|
||||
def help_defval_for_bool(otype: str) -> str:
|
||||
if otype == 'bool-set':
|
||||
return 'no'
|
||||
return 'yes'
|
||||
|
||||
|
||||
class PrintHelpForSeq:
|
||||
|
||||
allow_pager = True
|
||||
|
|
@ -424,10 +430,7 @@ def wa(text: str, indent: int = 0, leading_indent: int | None = None) -> None:
|
|||
a(' ' + ', '.join(map(green, sorted(opt['aliases'], reverse=True))))
|
||||
defval = opt.get('default')
|
||||
if (otype := opt.get('type', '')).startswith('bool-'):
|
||||
if otype == 'bool-set':
|
||||
blocks[-1] += italic('[=no]')
|
||||
else:
|
||||
blocks[-1] += italic('[=yes]')
|
||||
blocks[-1] += italic(f'[={help_defval_for_bool(otype)}]')
|
||||
else:
|
||||
dt = f'''=[{italic(defval or '""')}]'''
|
||||
blocks[-1] += dt
|
||||
|
|
@ -495,10 +498,7 @@ def seq_as_rst(
|
|||
continue # hidden option
|
||||
defn = '.. option:: '
|
||||
if (otype := opt.get('type', '')).startswith('bool-'):
|
||||
if otype == 'bool-set':
|
||||
val_name = ' [=yes]'
|
||||
else:
|
||||
val_name = ' [=no]'
|
||||
val_name = f' [={help_defval_for_bool(otype)}]'
|
||||
else:
|
||||
val_name = ' <{}>'.format(opt['dest'].upper())
|
||||
a(defn + ', '.join(o + val_name for o in sorted(opt['aliases'])))
|
||||
|
|
|
|||
Loading…
Reference in a new issue