-
Notifications
You must be signed in to change notification settings - Fork 1
/
update-doc.py
executable file
·31 lines (24 loc) · 1.02 KB
/
update-doc.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
#!/usr/bin/env python3
import re
import subprocess
def run_command(cmd):
return subprocess.run(['bash', '-c', cmd], capture_output=True, check=True).stdout.decode("utf-8").strip("\n")
output = ''
with open('README.md', 'r', encoding='utf-8') as file_handler:
is_between_placeholders = False
for line in file_handler:
matches = re.match(r'\[\/\/\]\: \<\> \(command-placeholder-start "(.*)"\)', line)
if not is_between_placeholders and matches is not None:
is_between_placeholders = True
output += line
output += "```\n%s\n```\n" % (run_command(matches.group(1)))
continue
matches = re.match(r'\[\/\/\]\: \<\> \(command-placeholder-end\)', line)
if is_between_placeholders and matches is not None:
is_between_placeholders = False
output += line
continue
if not is_between_placeholders:
output += line
with open('README.md', 'w', encoding='utf-8') as file_handler:
file_handler.write(output)