forked from iGio90/frick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_doc_generator.py
68 lines (56 loc) · 1.77 KB
/
commands_doc_generator.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
58
59
60
61
62
63
64
65
66
67
68
import pytablewriter
import sys
from main import Command
writer = pytablewriter.MarkdownTableWriter()
writer.table_name = "commands list"
writer.header_list = ["command", "short", "info"]
writer.value_matrix = []
writer.margin = 2
current_module = sys.modules['main']
cmds = {}
for key in dir(current_module):
attr = getattr(current_module, key)
if isinstance(attr, type):
try:
if issubclass(attr, Command):
cmd = attr(None)
info = cmd.get_command_info()
if info is not None:
cmds[info['name']] = info
except:
continue
subs = {}
for cmd in sorted(cmds):
cmd_info = cmds[cmd]
st = ''
info = ''
if 'shortcuts' in cmd_info:
st = ','.join(sorted(cmd_info['shortcuts']))
if 'info' in cmd_info:
info = cmd_info['info']
if 'sub' in cmd_info:
subs[cmd] = cmd_info['sub']
writer.value_matrix.append([cmd, st, info])
writer.write_table()
def iter_subs(subs):
print('---')
next_subs = {}
for cmd in sorted(subs):
writer.table_name = "%s sub commands" % cmd
writer.value_matrix = []
cmd_info_arr = subs[cmd]
for cmd_info in sorted(cmd_info_arr, key=lambda x: x['name']):
st = ''
info = ''
if 'shortcuts' in cmd_info:
st = ','.join(sorted(cmd_info['shortcuts']))
if 'info' in cmd_info:
info = cmd_info['info']
if 'sub' in cmd_info:
next_subs[cmd + ' ' + cmd_info['name']] = cmd_info['sub']
writer.value_matrix.append([cmd_info['name'], st, info])
writer.write_table()
if len(next_subs) > 0:
iter_subs(next_subs)
next_subs = {}
iter_subs(subs)