Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3593dfc

Browse files
Ellie-YenLee-W
authored andcommitted
ci(scripts): a script to gen cli help screenshots
1 parent daef1d3 commit 3593dfc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

‎scripts/gen_cli_help_screenshots.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import subprocess
3+
from pathlib import Path
4+
5+
from rich.console import Console
6+
7+
from commitizen.cli import data
8+
9+
project_root = Path(__file__).parent.parent.absolute()
10+
images_root = project_root / Path("docs") / Path("images") / Path("cli_help")
11+
12+
13+
def gen_cli_help_screenshots() -> None:
14+
"""Generate the screenshot for help message on each cli command and save them as svg files."""
15+
if not os.path.exists(images_root):
16+
os.makedirs(images_root)
17+
print(f"Created {images_root}")
18+
19+
help_cmds = _list_help_cmds()
20+
for cmd in help_cmds:
21+
file_name = f"{cmd.replace(' ', '_').replace('-', '_')}.svg"
22+
_export_cmd_as_svg(cmd, f"{images_root}/{file_name}")
23+
24+
25+
def _list_help_cmds() -> list[str]:
26+
cmds = [f"{data['prog']} --help"] + [
27+
f"{data['prog']} {sub_c['name'] if isinstance(sub_c['name'], str) else sub_c['name'][0]} --help"
28+
for sub_c in data["subcommands"]["commands"]
29+
]
30+
31+
return cmds
32+
33+
34+
def _export_cmd_as_svg(cmd: str, file_name: str) -> None:
35+
stdout = subprocess.run(cmd, shell=True, capture_output=True).stdout.decode("utf-8")
36+
console = Console(record=True, width=80)
37+
console.print(f"$ {cmd}\n{stdout}")
38+
console.save_svg(file_name, title="")
39+
40+
41+
if __name__ == "__main__":
42+
gen_cli_help_screenshots()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /