-
Notifications
You must be signed in to change notification settings - Fork 1
/
document_commands.py
executable file
·36 lines (32 loc) · 1.06 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
#!/usr/bin/env python
from __future__ import print_function
from n_utils import COMMAND_MAPPINGS, PATH_COMMANDS, NDT_AND_CONSOLE
from subprocess import Popen, PIPE
import locale
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("'", "\\'")
for command in sorted(COMMAND_MAPPINGS.keys()):
if command in CONSOLE_PREFERRED:
continue
print("## `ndt " + command + "`")
print("")
print("```bash")
print(do_call(["ndt", command, "-h"]))
print("```\n")
for command in CONSOLE_PREFERRED:
print("## `[ndt ]" + command + "`")
print("")
print("```bash")
print(do_call([command, "-h"]))
print("```\n")
for script in sorted(PATH_COMMANDS):
name = script.split("/")[-1]
print("## `" + name + "`")
print("")
print("```bash")
print(do_call([name, "-h"]))
print("```\n")