|
6 | 6 | import sys |
7 | 7 | import textwrap |
8 | 8 | from collections import defaultdict |
9 | | -from typing import Dict, List, Optional |
| 9 | +from typing import Dict, List, Optional, Tuple |
10 | 10 |
|
11 | 11 | from rich import box |
12 | 12 | from rich import print as rprint |
@@ -264,32 +264,42 @@ def _help_action_print_body_args( |
264 | 264 | console.print(f"[bold]Arguments{f' ({title})' if title else ''}:[/]") |
265 | 265 |
|
266 | 266 | for group in _help_group_arguments(args): |
267 | | - for arg in group: |
268 | | - metadata = [] |
| 267 | + for option in _help_group_options(group): |
| 268 | + if option[0] is not None: |
| 269 | + # If this is an option with an explicit title, |
| 270 | + # display it here |
| 271 | + console.print( |
| 272 | + Padding.indent(f"[bold underline]{option[0]}[/]:", 4), |
| 273 | + ) |
269 | 274 |
|
270 | | - if op.method in {"post", "put"} and arg.required: |
271 | | - metadata.append("required") |
| 275 | + for arg in option[1]: |
| 276 | + metadata = [] |
272 | 277 |
|
273 | | - if arg.format == "json": |
274 | | - metadata.append("JSON") |
| 278 | + if op.method in {"post", "put"} and arg.required: |
| 279 | + metadata.append("required") |
275 | 280 |
|
276 | | - if arg.nullable: |
277 | | - metadata.append("nullable") |
| 281 | + if arg.format == "json": |
| 282 | + metadata.append("JSON") |
278 | 283 |
|
279 | | - if arg.is_parent: |
280 | | - metadata.append("conflicts with children") |
| 284 | + if arg.nullable: |
| 285 | + metadata.append("nullable") |
281 | 286 |
|
282 | | - prefix = f" ({', '.join(metadata)})" if len(metadata) > 0 else "" |
| 287 | + if arg.is_parent: |
| 288 | + metadata.append("conflicts with children") |
283 | 289 |
|
284 | | - arg_text = Text.from_markup( |
285 | | - f"[bold green]--{arg.path}[/][bold]{prefix}:[/] {arg.description_rich}" |
286 | | - ) |
| 290 | + prefix = ( |
| 291 | + f" ({', '.join(metadata)})" if len(metadata) > 0 else "" |
| 292 | + ) |
287 | 293 |
|
288 | | - console.print( |
289 | | - Padding.indent(arg_text, (arg.depth * 2) + 2), |
290 | | - ) |
| 294 | + arg_text = Text.from_markup( |
| 295 | + f"[bold green]--{arg.path}[/][bold]{prefix}:[/] {arg.description_rich}" |
| 296 | + ) |
291 | 297 |
|
292 | | - console.print() |
| 298 | + console.print( |
| 299 | + Padding.indent(arg_text, (arg.depth * 2) + 2), |
| 300 | + ) |
| 301 | + |
| 302 | + console.print() |
293 | 303 |
|
294 | 304 |
|
295 | 305 | def _help_group_arguments( |
@@ -346,3 +356,15 @@ def _help_group_arguments( |
346 | 356 | result += groups |
347 | 357 |
|
348 | 358 | return result |
| 359 | + |
| 360 | + |
| 361 | +def _help_group_options( |
| 362 | + args: List[OpenAPIRequestArg], |
| 363 | +) -> List[Tuple[Optional[str], List[OpenAPIRequestArg]]]: |
| 364 | + groups = defaultdict(list) |
| 365 | + |
| 366 | + for arg in args: |
| 367 | + group_key = " - ".join(arg.option_path) if arg.option_path else None |
| 368 | + groups[group_key].append(arg) |
| 369 | + |
| 370 | + return sorted(groups.items(), key=lambda v: v[0] or "") |
0 commit comments