-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc-insert-help.py
More file actions
executable file
·49 lines (36 loc) · 1.05 KB
/
doc-insert-help.py
File metadata and controls
executable file
·49 lines (36 loc) · 1.05 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
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import re
import subprocess
import sys
from pathlib import Path
FILE = Path("README.md")
START = "<!-- BEGIN CLI HELP -->"
END = "<!-- END CLI HELP -->"
COMMAND = ["./install", "--help"]
def main():
try:
result = subprocess.run(
COMMAND,
capture_output=True,
text=True,
check=True,
)
except subprocess.CalledProcessError as e:
print("Failed to run command:", e, file=sys.stderr)
sys.exit(1)
help_text = result.stdout.strip()
content = FILE.read_text()
pattern = re.compile(
rf"{re.escape(START)}.*?{re.escape(END)}",
re.DOTALL,
)
if not pattern.search(content):
print("Markers not found in README.md", file=sys.stderr)
sys.exit(1)
replacement = f"{START}\n\n```text\n{help_text}\n```\n\n{END}"
updated = pattern.sub(replacement, content)
if updated != content:
_ = FILE.write_text(updated)
print("Updated CLI help in README.md")
if __name__ == "__main__":
main()