2022-11-30 22:30:45 +01:00
|
|
|
import json
|
|
|
|
import sys
|
|
|
|
|
|
|
|
header = """
|
|
|
|
# Mailserver options
|
|
|
|
|
|
|
|
## `mailserver`
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
template = """
|
|
|
|
`````{{option}} {key}
|
|
|
|
{description}
|
|
|
|
|
|
|
|
{type}
|
|
|
|
{default}
|
|
|
|
{example}
|
|
|
|
`````
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = open(sys.argv[1])
|
|
|
|
options = json.load(f)
|
|
|
|
|
2025-05-08 01:40:37 +02:00
|
|
|
groups = [
|
|
|
|
"mailserver.loginAccounts",
|
|
|
|
"mailserver.certificate",
|
|
|
|
"mailserver.dkim",
|
|
|
|
"mailserver.dmarcReporting",
|
|
|
|
"mailserver.fullTextSearch",
|
|
|
|
"mailserver.redis",
|
|
|
|
"mailserver.ldap",
|
|
|
|
"mailserver.monitoring",
|
|
|
|
"mailserver.backup",
|
|
|
|
"mailserver.borgbackup",
|
|
|
|
]
|
|
|
|
|
2022-11-30 22:30:45 +01:00
|
|
|
|
|
|
|
def render_option_value(opt, attr):
|
2025-05-08 01:38:42 +02:00
|
|
|
if attr not in opt:
|
|
|
|
return ""
|
|
|
|
|
2025-05-08 01:40:37 +02:00
|
|
|
if isinstance(opt[attr], dict) and "_type" in opt[attr]:
|
|
|
|
if opt[attr]["_type"] == "literalExpression":
|
|
|
|
if "\n" in opt[attr]["text"]:
|
2025-05-08 06:25:55 +02:00
|
|
|
text = opt[attr]["text"].rstrip("\n")
|
|
|
|
res = f"\n```nix\n{text}\n```"
|
2025-05-08 01:38:42 +02:00
|
|
|
else:
|
2025-05-08 06:25:55 +02:00
|
|
|
res = f"```{opt[attr]["text"]}```"
|
2025-05-08 01:40:37 +02:00
|
|
|
elif opt[attr]["_type"] == "literalMD":
|
|
|
|
res = opt[attr]["text"]
|
2025-05-08 01:38:42 +02:00
|
|
|
else:
|
|
|
|
assert RuntimeError(f"Unhandled option type {opt[attr]["_type"]}")
|
|
|
|
else:
|
|
|
|
s = str(opt[attr])
|
|
|
|
if s == "":
|
|
|
|
res = '`""`'
|
2025-05-08 01:40:37 +02:00
|
|
|
elif "\n" in s:
|
2025-05-08 06:25:55 +02:00
|
|
|
res = f"\n```\n{s.rstrip("\n")}\n```"
|
2025-05-08 01:38:42 +02:00
|
|
|
else:
|
2025-05-08 06:25:55 +02:00
|
|
|
res = f"```{s}```"
|
2025-05-08 01:40:37 +02:00
|
|
|
|
|
|
|
return "- " + attr + ": " + res # type: ignore
|
2025-05-08 01:38:42 +02:00
|
|
|
|
2022-11-30 22:30:45 +01:00
|
|
|
|
|
|
|
def print_option(opt):
|
2025-05-08 01:40:37 +02:00
|
|
|
if isinstance(opt["description"], dict) and "_type" in opt["description"]: # mdDoc
|
|
|
|
description = opt["description"]["text"]
|
2022-11-30 22:30:45 +01:00
|
|
|
else:
|
2025-05-08 01:40:37 +02:00
|
|
|
description = opt["description"]
|
|
|
|
print(
|
|
|
|
template.format(
|
|
|
|
key=opt["name"],
|
|
|
|
description=description or "",
|
2025-05-08 06:25:55 +02:00
|
|
|
type=f"- type: ```{opt["type"]}```",
|
2025-05-08 01:40:37 +02:00
|
|
|
default=render_option_value(opt, "default"),
|
|
|
|
example=render_option_value(opt, "example"),
|
|
|
|
)
|
|
|
|
)
|
2022-11-30 22:30:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
print(header)
|
|
|
|
for opt in options:
|
2025-05-08 01:40:37 +02:00
|
|
|
if any([opt["name"].startswith(c) for c in groups]):
|
2022-11-30 22:30:45 +01:00
|
|
|
continue
|
|
|
|
print_option(opt)
|
|
|
|
|
|
|
|
for c in groups:
|
2025-05-08 06:25:55 +02:00
|
|
|
print(f"## `{c}`\n")
|
2022-11-30 22:30:45 +01:00
|
|
|
for opt in options:
|
2025-05-08 01:40:37 +02:00
|
|
|
if opt["name"].startswith(c):
|
2022-11-30 22:30:45 +01:00
|
|
|
print_option(opt)
|