Skip to content

Commit f05563d

Browse files
committed
Fixed make_command_docs.py so it now generates the command docs from the help text again. Removed a lot of the hacks I used the first time.
1 parent 9d050db commit f05563d

1 file changed

Lines changed: 8 additions & 40 deletions

File tree

make_command_docs.py

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,6 @@
1414
import subprocess
1515
import sys
1616

17-
command_headings = dict()
18-
19-
command_headings[('copy')] = "Copy data object from src to dst"
20-
command_headings[('change', 'bid')] = "Change existing bid by id"
21-
command_headings[('create', 'account')] = "Create account (command line account creation no longer supported)"
22-
command_headings[('create', 'instance')] = "Create instance"
23-
command_headings[('destroy', 'instance')] = "Destroy instance"
24-
command_headings[('generate', 'pdf-invoices')] = "Generate pdf-invoices"
25-
command_headings[('label', 'instance')] = "Label instance"
26-
command_headings[('list', 'machine')] = "List machine for rent"
27-
command_headings[('login')] = "Login (command line login no longer supported)"
28-
command_headings[('remove', 'defjob')] = "Remove default job"
29-
command_headings[('scp-url')] = "scp-url"
30-
command_headings[('search', 'offers')] = "Search offers"
31-
command_headings[('set', 'api-key')] = "Set api-key"
32-
command_headings[('set', 'defjob')] = "Set default job"
33-
command_headings[('set', 'min-bid')] = "Set minimum bid"
34-
command_headings[('show', 'instances')] = "Show instances we are renting"
35-
command_headings[('show', 'invoices')] = "Show invoices"
36-
command_headings[('show', 'machines')] = "Show machines we are offering for rent"
37-
command_headings[('show', 'user')] = "Show user account information"
38-
command_headings[('ssh-url')] = "ssh-url"
39-
command_headings[('start', 'instance')] = "Start instance"
40-
command_headings[('stop', 'instance')] = "Stop instance"
41-
command_headings[('unlist', 'machine')] = "Unlist machine"
42-
43-
4417
def snip_lines_from_text(text: str, start_line: int, end_line: int, invert: bool = False):
4518
text_lines = text.split("\n")
4619
if invert:
@@ -68,44 +41,39 @@ def run_cmd_and_capture_output(verb: str, obj: str = None, direct_obj: str = Non
6841

6942
def run_help_for_commands(lines):
7043
help_text = ""
71-
lines.sort()
7244
i = 1
7345
for line in lines:
7446
cmd_output = ""
75-
command_parts = re.split(r"\s+", line.strip())
47+
line_parts = re.split(r"\s{2,}", line.strip())
48+
command_parts = re.split(r"\s+", line_parts[0])
49+
if len(line_parts) < 2:
50+
line_parts.append("")
7651
print(f"{i}: {command_parts}")
7752
i += 1
7853
num_command_parts = len(command_parts)
7954
if num_command_parts == 0:
8055
continue
8156
if num_command_parts == 3:
8257
cmd_output = run_cmd_and_capture_output(command_parts[0], command_parts[1], command_parts[2])
83-
help_text += f"#### {command_headings[(command_parts[0], command_parts[1], command_parts[2])]}\n\n"
8458
if num_command_parts == 2:
8559
cmd_output = run_cmd_and_capture_output(command_parts[0], command_parts[1])
86-
help_text += f"#### {command_headings[(command_parts[0], command_parts[1])]}\n\n"
8760
elif num_command_parts == 1:
8861
cmd_output = run_cmd_and_capture_output(command_parts[0])
89-
help_text += f"#### {command_headings[(command_parts[0])]}\n\n"
62+
63+
help_text += f"#### {line_parts[0]} -- {line_parts[1]}\n\n"
9064
help_text += f"```\n{cmd_output}\n```\n---\n"
9165

9266
return help_text
9367

9468

9569
main_help_text = run_cmd_and_capture_output("", "")
96-
# command_index = make_lines_into_links(snip_lines_from_text(main_help_text, 4, 27)) + "\n\n"
70+
snipped_help_text = snip_lines_from_text(main_help_text, 4, 29)
71+
snipped_help_text = sorted(list(map(str.strip, snipped_help_text)))
9772

98-
99-
main_help_text = run_cmd_and_capture_output("", "")
100-
# main_help_text_lines = main_help_text.split("\n")
101-
snipped_help_text = snip_lines_from_text(main_help_text, 4, 28)
102-
#snipped_help_text = snipped_help_text.sort()
10373
command_help_text = run_help_for_commands(snipped_help_text)
104-
# main_help_text = "\n".join(snip_lines_from_text(main_help_text, 1, 27, True))
10574
main_help_text = f"```\n{main_help_text}\n```\n"
10675

10776

10877
with open("commands.md", "w") as fh:
109-
# fh.write(command_index)
11078
fh.write(main_help_text)
11179
fh.write(command_help_text)

0 commit comments

Comments
 (0)