-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocify.py
More file actions
executable file
·44 lines (33 loc) · 808 Bytes
/
docify.py
File metadata and controls
executable file
·44 lines (33 loc) · 808 Bytes
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
#!/bin/python3
# Copyright Red Hat
#
# docify.py - Convert command output into MD/groff example notation.
#
# This file is part of the snapshot manager project.
#
# SPDX-License-Identifier: Apache-2.0
from subprocess import run, PIPE, STDOUT
import sys
def print_man(command):
print(".EX")
for line in command:
print(line)
print(".EE")
def print_md(command):
print("```")
for line in command:
print(line)
print("```")
def main(argv):
argv.pop(0)
cmd = run(argv, stdout=PIPE, stderr=STDOUT)
output = cmd.stdout.decode("utf8").splitlines()
command = ["# " + " ".join(argv)] + output
for line in command:
print(line)
print()
print_md(command)
print()
print_man(command)
if __name__ == "__main__":
main(sys.argv)