forked from fauna/fauna-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.py
57 lines (45 loc) · 1.23 KB
/
readme.py
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
50
51
52
53
54
55
56
57
import re
import subprocess
def run(command: list[str]) -> str:
result = subprocess.check_output(command)
return result.decode("utf8")
with open("README.md", "r") as file:
data = file.read()
subprocess.call("yarn build", shell=True)
in_commands = False
i = 0
lines = data.split("\n")
command = ""
while i < len(lines):
line = lines[i]
i += 1
if line == "<!-- commands -->":
in_commands = True
if not in_commands:
continue
if line == "<!-- commandsstop -->":
break
match = re.search("###? `(.+)`", line)
if match != None:
command = match.group(1).split(" ")
if line == "```sh":
start = i
end = None
while i < len(lines):
line = lines[i]
i += 1
if line == "```":
end = i - 1
break
if end != None:
print(f"updated command {command}")
result = run(["./bin/run", *command[1:], "--help"]).strip()
# remove the VERSION section
if command == ["fauna", "help"]:
m = re.search("VERSION.*\n.*\n\n", result)
result = result[:m.start()] + result[m.end():]
result = result.split("\n")
lines[start:end] = result
i += len(result) - (end - start)
with open("README.md", "w") as file:
file.write("\n".join(lines))