|
14 | 14 | import subprocess |
15 | 15 | import sys |
16 | 16 |
|
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 | | - |
44 | 17 | def snip_lines_from_text(text: str, start_line: int, end_line: int, invert: bool = False): |
45 | 18 | text_lines = text.split("\n") |
46 | 19 | if invert: |
@@ -68,44 +41,39 @@ def run_cmd_and_capture_output(verb: str, obj: str = None, direct_obj: str = Non |
68 | 41 |
|
69 | 42 | def run_help_for_commands(lines): |
70 | 43 | help_text = "" |
71 | | - lines.sort() |
72 | 44 | i = 1 |
73 | 45 | for line in lines: |
74 | 46 | 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("") |
76 | 51 | print(f"{i}: {command_parts}") |
77 | 52 | i += 1 |
78 | 53 | num_command_parts = len(command_parts) |
79 | 54 | if num_command_parts == 0: |
80 | 55 | continue |
81 | 56 | if num_command_parts == 3: |
82 | 57 | 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" |
84 | 58 | if num_command_parts == 2: |
85 | 59 | 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" |
87 | 60 | elif num_command_parts == 1: |
88 | 61 | 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" |
90 | 64 | help_text += f"```\n{cmd_output}\n```\n---\n" |
91 | 65 |
|
92 | 66 | return help_text |
93 | 67 |
|
94 | 68 |
|
95 | 69 | 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))) |
97 | 72 |
|
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() |
103 | 73 | 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)) |
105 | 74 | main_help_text = f"```\n{main_help_text}\n```\n" |
106 | 75 |
|
107 | 76 |
|
108 | 77 | with open("commands.md", "w") as fh: |
109 | | -# fh.write(command_index) |
110 | 78 | fh.write(main_help_text) |
111 | 79 | fh.write(command_help_text) |
0 commit comments