scripts/generate-options: fix typing issue

This commit is contained in:
Martin Weinelt 2025-05-08 01:38:42 +02:00
parent 1615c93511
commit f9fcbe9430
No known key found for this signature in database
GPG Key ID: 87C1E9888F856759

View File

@ -33,27 +33,29 @@ groups = ["mailserver.loginAccounts",
"mailserver.borgbackup"] "mailserver.borgbackup"]
def render_option_value(opt, attr): def render_option_value(opt, attr):
if attr in opt: if attr not in opt:
if isinstance(opt[attr], dict) and '_type' in opt[attr]: return ""
if opt[attr]['_type'] == 'literalExpression':
if '\n' in opt[attr]['text']: if isinstance(opt[attr], dict) and '_type' in opt[attr]:
res = '\n```nix\n' + opt[attr]['text'].rstrip('\n') + '\n```' if opt[attr]['_type'] == 'literalExpression':
else: if '\n' in opt[attr]['text']:
res = '```{}```'.format(opt[attr]['text']) res = '\n```nix\n' + opt[attr]['text'].rstrip('\n') + '\n```'
elif opt[attr]['_type'] == 'literalMD': else:
res = opt[attr]['text'] res = '```{}```'.format(opt[attr]['text'])
else: elif opt[attr]['_type'] == 'literalMD':
s = str(opt[attr]) res = opt[attr]['text']
if s == "": else:
res = '`""`' assert RuntimeError(f"Unhandled option type {opt[attr]["_type"]}")
elif '\n' in s: else:
res = '\n```\n' + s.rstrip('\n') + '\n```' s = str(opt[attr])
else: if s == "":
res = '```{}```'.format(s) res = '`""`'
res = '- ' + attr + ': ' + res elif '\n' in s:
else: res = '\n```\n' + s.rstrip('\n') + '\n```'
res = "" else:
return res res = '```{}```'.format(s)
return '- ' + attr + ': ' + res # type: ignore
def print_option(opt): def print_option(opt):
if isinstance(opt['description'], dict) and '_type' in opt['description']: # mdDoc if isinstance(opt['description'], dict) and '_type' in opt['description']: # mdDoc