64 lines
1.6 KiB
Python
Executable File
64 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
parser = argparse.ArgumentParser(prog="generate-options-docs.py")
|
|
parser.add_argument("options_json_file", type=Path)
|
|
|
|
args = parser.parse_args()
|
|
|
|
module_options = json.loads(args.options_json_file.read_text())
|
|
|
|
print("""---
|
|
hide:
|
|
- navigation
|
|
---
|
|
|
|
# Options
|
|
|
|
""")
|
|
|
|
def format_option_value(option_value):
|
|
if not isinstance(option_value, dict):
|
|
option_value = {
|
|
"_type": "literalExpression",
|
|
"text": str(option_value),
|
|
}
|
|
|
|
match option_value["_type"]:
|
|
case "literalExpression":
|
|
if "\n" in option_value["text"]:
|
|
return f"```\n{option_value['text']}\n```"
|
|
else:
|
|
return f"```\n{option_value['text']}\n```"
|
|
|
|
case "literalMD":
|
|
return option_value["text"]
|
|
case other_value_type:
|
|
raise Exception(f"Unhandle option value type {other_value_type}")
|
|
|
|
|
|
def print_option(option):
|
|
print(f"## `{option['name']}`")
|
|
print("")
|
|
if "description" in option and option["description"] is not None:
|
|
print(option['description'])
|
|
print("")
|
|
if "type" in option:
|
|
print("**Type:**")
|
|
print(f"`{option['type']}`")
|
|
print("")
|
|
if "default" in option:
|
|
print(f"**Default:**")
|
|
print(format_option_value(option['default']))
|
|
print("")
|
|
if "example" in option:
|
|
print(f"**Example:**")
|
|
print(format_option_value(option['example']))
|
|
print("")
|
|
|
|
for option in module_options:
|
|
print_option(option)
|