-
Notifications
You must be signed in to change notification settings - Fork 2
/
document_commands.py
executable file
·54 lines (41 loc) · 1.48 KB
/
document_commands.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
#!/usr/bin/env python3
import locale
import sys
from subprocess import PIPE, Popen
from n_utils import COMMAND_MAPPINGS, NDT_AND_CONSOLE, PATH_COMMANDS
SYS_ENCODING = locale.getpreferredencoding()
CONSOLE_PREFERRED = sorted([cmd.split("=")[0] for cmd in NDT_AND_CONSOLE])
def do_call(command):
proc = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, err = proc.communicate()
return (output + err).decode(SYS_ENCODING).strip().replace("'", "\\'")
def document_commands():
print(
"*This document is autogenerated by "
"[https://github.com/NitorCreations/nameless-deploy-tools/blob/master/document_commands.py](document_commands.py). " # noqa: E501
"Do not edit by hand!*\n"
)
for command in sorted(COMMAND_MAPPINGS.keys()):
if command in CONSOLE_PREFERRED:
continue
print(f"## `ndt {command}`\n")
print("```bash")
print(do_call(["ndt", command, "-h"]))
print("```\n")
for command in CONSOLE_PREFERRED:
print(f"## `[ndt ]{command}`\n")
print("```bash")
print(do_call([command, "-h"]))
print("```\n")
for script in sorted(PATH_COMMANDS):
name = script.split("/")[-1]
print(f"## `{name}`\n")
print("```bash")
print(do_call([name, "-h"]))
print("```\n")
if __name__ == "__main__":
try:
document_commands()
except KeyboardInterrupt:
# handle CTRL-C gracefully
sys.exit("\ninterrupted")