|
3 | 3 | help pages. |
4 | 4 | """ |
5 | 5 |
|
| 6 | +import sys |
6 | 7 | import textwrap |
7 | 8 | from collections import defaultdict |
8 | | -from typing import List, Optional |
| 9 | +from typing import Dict, List, Optional |
9 | 10 |
|
10 | 11 | from rich import box |
11 | 12 | from rich import print as rprint |
12 | 13 | from rich.console import Console |
13 | 14 | from rich.padding import Padding |
14 | | -from rich.table import Table |
| 15 | +from rich.table import Column, Table |
15 | 16 | from rich.text import Text |
16 | 17 |
|
17 | 18 | from linodecli import plugins |
@@ -140,6 +141,36 @@ def print_help_default(): |
140 | 141 | ) |
141 | 142 |
|
142 | 143 |
|
| 144 | +def print_help_command_actions( |
| 145 | + ops: Dict[str, Dict[str, OpenAPIOperation]], |
| 146 | + command: Optional[str], |
| 147 | + file=sys.stdout, |
| 148 | +): |
| 149 | + """ |
| 150 | + Prints the help page for a single command, including all actions |
| 151 | + under the given command. |
| 152 | +
|
| 153 | + :param ops: A dictionary mapping CLI commands -> actions -> operations. |
| 154 | + :param command: The command to print the help page for. |
| 155 | + """ |
| 156 | + |
| 157 | + print(f"linode-cli {command} [ACTION]\n\nAvailable actions: ", file=file) |
| 158 | + |
| 159 | + content = [ |
| 160 | + [", ".join([action, *op.action_aliases]), op.summary] |
| 161 | + for action, op in sorted(ops[command].items(), key=lambda v: v[0]) |
| 162 | + ] |
| 163 | + |
| 164 | + table = Table( |
| 165 | + Column(header="action", no_wrap=True), |
| 166 | + Column(header="summary", style="cyan"), |
| 167 | + ) |
| 168 | + for row in content: |
| 169 | + table.add_row(*row) |
| 170 | + |
| 171 | + rprint(table, file=file) |
| 172 | + |
| 173 | + |
143 | 174 | def print_help_action( |
144 | 175 | cli: "CLI", command: Optional[str], action: Optional[str] |
145 | 176 | ): |
|
0 commit comments