viv/scripts/generate-svgs.py

79 lines
1.5 KiB
Python
Raw Normal View History

2023-08-03 18:17:23 -05:00
#!/usr/bin/env python3
2023-06-01 00:04:02 -05:00
from pathlib import Path
from subprocess import run
from textwrap import dedent
from typing import Tuple
DOCS_PATH = Path(__file__).parent.parent / "docs"
(SAVE_PATH := DOCS_PATH / "svgs").mkdir(exist_ok=True)
VIV = Path(__file__).parent.parent / "src" / "viv" / "viv.py"
CLI_DOC_PATH = DOCS_PATH / "cli.md"
2023-08-06 21:56:15 -05:00
(
cmds := dict.fromkeys(
(
"list",
"exe",
"remove",
"manage",
"freeze",
"shim",
"run",
),
[],
)
).update({"manage": ["update", "purge", "show", "install"]})
2023-06-01 00:04:02 -05:00
cli_doc = """
# cli
2023-08-05 12:08:31 -05:00
![help](./svgs/viv-help.svg)
2023-06-01 00:04:02 -05:00
"""
def yartsu(output: Path, args: Tuple[str, str] | str) -> None:
if isinstance(args, str):
args = (args,)
cmd = [
VIV,
"run",
"-k",
"yartsu",
"--",
"-w",
"70",
"-o",
output,
"--",
"viv",
*args,
"--help",
]
run(cmd)
yartsu(SAVE_PATH / "viv-help.svg", "")
for cmd, subcmds in cmds.items():
p = SAVE_PATH / f"viv-{cmd}-help.svg"
cli_doc += dedent(
f"""
## {cmd}
2023-08-05 12:08:31 -05:00
![cmd](./svgs/{p.name})
2023-06-01 00:04:02 -05:00
"""
)
yartsu(p, cmd)
for subcmd in subcmds:
p_sub = SAVE_PATH / f"viv-{cmd}-{subcmd}-help.svg"
cli_doc += dedent(
f"""
### {cmd} {subcmd}
2023-08-05 12:08:31 -05:00
![cmd](./svgs/{p_sub.name})
2023-06-01 00:04:02 -05:00
"""
)
yartsu(p_sub, [cmd, subcmd])
CLI_DOC_PATH.write_text(cli_doc)