diff --git a/scripts/generate-options.py b/scripts/generate-options.py index 75a25ae..652f89a 100644 --- a/scripts/generate-options.py +++ b/scripts/generate-options.py @@ -33,27 +33,29 @@ groups = ["mailserver.loginAccounts", "mailserver.borgbackup"] def render_option_value(opt, attr): - if attr in opt: - if isinstance(opt[attr], dict) and '_type' in opt[attr]: - if opt[attr]['_type'] == 'literalExpression': - if '\n' in opt[attr]['text']: - res = '\n```nix\n' + opt[attr]['text'].rstrip('\n') + '\n```' - else: - res = '```{}```'.format(opt[attr]['text']) - elif opt[attr]['_type'] == 'literalMD': - res = opt[attr]['text'] - else: - s = str(opt[attr]) - if s == "": - res = '`""`' - elif '\n' in s: - res = '\n```\n' + s.rstrip('\n') + '\n```' - else: - res = '```{}```'.format(s) - res = '- ' + attr + ': ' + res - else: - res = "" - return res + if attr not in opt: + return "" + + if isinstance(opt[attr], dict) and '_type' in opt[attr]: + if opt[attr]['_type'] == 'literalExpression': + if '\n' in opt[attr]['text']: + res = '\n```nix\n' + opt[attr]['text'].rstrip('\n') + '\n```' + else: + res = '```{}```'.format(opt[attr]['text']) + elif opt[attr]['_type'] == 'literalMD': + res = opt[attr]['text'] + else: + assert RuntimeError(f"Unhandled option type {opt[attr]["_type"]}") + else: + s = str(opt[attr]) + if s == "": + res = '`""`' + elif '\n' in s: + res = '\n```\n' + s.rstrip('\n') + '\n```' + else: + res = '```{}```'.format(s) + + return '- ' + attr + ': ' + res # type: ignore def print_option(opt): if isinstance(opt['description'], dict) and '_type' in opt['description']: # mdDoc