From 44cca80a0caeb6ca20f7f4f0e208482a8cd8438b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 29 Apr 2025 08:43:21 +0530 Subject: [PATCH] DRYer --- kitty/cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kitty/cli.py b/kitty/cli.py index ca87d8749..22d06e5c2 100644 --- a/kitty/cli.py +++ b/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'])))