-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathgen_cli_help_screenshots.py
More file actions
41 lines (29 loc) · 1.29 KB
/
gen_cli_help_screenshots.py
File metadata and controls
41 lines (29 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import subprocess
from itertools import chain
from pathlib import Path
from rich.console import Console
from commitizen.cli import data
def gen_cli_help_screenshots() -> None:
"""Generate the screenshot for help message on each cli command and save them as svg files."""
images_root = Path(__file__).parent.parent / "docs" / "images" / "cli_help"
images_root.mkdir(parents=True, exist_ok=True)
cz_commands = (
command["name"] if isinstance(command["name"], str) else command["name"][0]
for command in data["subcommands"]["commands"] # type: ignore[index]
)
for cmd in chain(
["cz --help"], (f"cz {cz_command} --help" for cz_command in cz_commands)
):
file_name = f"{cmd.replace(' ', '_').replace('-', '_')}.svg"
_export_cmd_as_svg(cmd, images_root / file_name)
def _export_cmd_as_svg(cmd: str, file_path: Path) -> None:
console = Console(record=True, width=80, file=open(os.devnull, "w"))
print("Processing command:", cmd)
console.print(f"$ {cmd}")
stdout = subprocess.run(cmd, shell=True, capture_output=True).stdout.decode("utf-8")
console.print(stdout)
console.save_svg(file_path.as_posix(), title="")
print("Saved to:", file_path.as_posix())
if __name__ == "__main__":
gen_cli_help_screenshots()