2021-07-14 08:06:58 +00:00
|
|
|
import json
|
|
|
|
import sys
|
2021-10-14 07:06:14 +00:00
|
|
|
import re
|
2021-07-14 08:06:58 +00:00
|
|
|
|
|
|
|
header = """
|
|
|
|
Mailserver Options
|
|
|
|
==================
|
|
|
|
|
|
|
|
mailserver
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
template = """
|
|
|
|
{key}
|
|
|
|
{line}
|
|
|
|
|
|
|
|
{description}
|
|
|
|
|
|
|
|
{type}
|
|
|
|
{default}
|
|
|
|
"""
|
|
|
|
|
|
|
|
f = open(sys.argv[1])
|
|
|
|
options = json.load(f)
|
|
|
|
|
2021-10-14 07:06:14 +00:00
|
|
|
options = {k: v for k, v in options.items()
|
|
|
|
if k.startswith("mailserver.")}
|
|
|
|
|
|
|
|
groups = ["mailserver.loginAccount",
|
|
|
|
"mailserver.certificate",
|
|
|
|
"mailserver.dkim",
|
|
|
|
"mailserver.fullTextSearch",
|
|
|
|
"mailserver.redis",
|
|
|
|
"mailserver.monitoring",
|
|
|
|
"mailserver.backup",
|
|
|
|
"mailserver.borg"]
|
2021-07-14 08:06:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_option(name, value):
|
2021-10-14 07:06:14 +00:00
|
|
|
if 'default' in value:
|
|
|
|
if value['default'] == "":
|
2022-01-21 14:06:14 +00:00
|
|
|
default = '``""``'
|
|
|
|
elif isinstance(value['default'], dict) and '_type' in value['default']:
|
|
|
|
if value['default']['_type'] == 'literalExpression':
|
|
|
|
default = '``{}``'.format(value['default']['text'])
|
|
|
|
if value['default']['_type'] == 'literalDocBook':
|
|
|
|
default = value['default']['text']
|
2021-07-14 08:06:58 +00:00
|
|
|
else:
|
2022-01-21 14:06:14 +00:00
|
|
|
default = '``{}``'.format(value['default'])
|
|
|
|
# Some default values contains OUTPUTPATHS which make the
|
|
|
|
# output not stable across nixpkgs updates.
|
|
|
|
default = re.sub('/nix/store/[\w.-]*/', '<OUTPUT-PATH>/', default) # noqa
|
|
|
|
default = '- Default: ' + default
|
2021-07-14 08:06:58 +00:00
|
|
|
else:
|
|
|
|
default = ""
|
|
|
|
print(template.format(
|
2021-10-14 07:06:14 +00:00
|
|
|
key=name,
|
|
|
|
line="-"*len(name),
|
|
|
|
description=value['description'],
|
|
|
|
type="- Type: ``{}``".format(value['type']),
|
2021-07-14 08:06:58 +00:00
|
|
|
default=default))
|
|
|
|
|
2021-10-14 07:06:14 +00:00
|
|
|
|
2021-07-14 08:06:58 +00:00
|
|
|
print(header)
|
|
|
|
for k, v in options.items():
|
|
|
|
if any([k.startswith(c) for c in groups]):
|
|
|
|
continue
|
|
|
|
print_option(k, v)
|
|
|
|
|
|
|
|
for c in groups:
|
|
|
|
print(c)
|
|
|
|
print("~"*len(c))
|
|
|
|
print()
|
|
|
|
for k, v in options.items():
|
|
|
|
if k.startswith(c):
|
|
|
|
print_option(k, v)
|