|
8 | 8 | from cappa.arg import Arg, ArgAction, ArgActionType, Group |
9 | 9 | from cappa.command import Command, Subcommand |
10 | 10 | from cappa.completion.types import Completion, FileCompletion |
11 | | -from cappa.help import format_subcommand_names |
| 11 | +from cappa.help import format_arg, format_subcommand_names |
12 | 12 | from cappa.invoke import fulfill_deps |
13 | 13 | from cappa.output import Exit, HelpExit, Output |
14 | 14 | from cappa.typing import T, assert_type |
@@ -372,20 +372,30 @@ def parse_option( |
372 | 372 | parse_state: ParseState, context: ParseContext, raw: RawOption |
373 | 373 | ) -> None: |
374 | 374 | if raw.name not in context.options: |
375 | | - possible_values = [ |
376 | | - name for name in context.options if name.startswith(raw.name) |
377 | | - ] |
| 375 | + possible_options: dict[str, Arg[Any]] = { |
| 376 | + name: arg |
| 377 | + for name, arg in context.options.items() |
| 378 | + if name.startswith(raw.name) |
| 379 | + } |
378 | 380 |
|
379 | 381 | if parse_state.provide_completions: |
380 | | - options = [ |
381 | | - Completion(option, help=context.options[option].help) |
382 | | - for option in possible_values |
383 | | - ] |
| 382 | + options: list[Completion] = [] |
| 383 | + for name, option in possible_options.items(): |
| 384 | + rendered_help = str( |
| 385 | + format_arg( |
| 386 | + parse_state.output.output_console, |
| 387 | + context.command.help_formatter, |
| 388 | + option, |
| 389 | + ) |
| 390 | + ).strip() |
| 391 | + completion = Completion(name, help=rendered_help, arg=option) |
| 392 | + options.append(completion) |
| 393 | + |
384 | 394 | raise CompletionAction(*options) |
385 | 395 |
|
386 | 396 | message = f"Unrecognized arguments: {raw.name}" |
387 | | - if possible_values: |
388 | | - message += f" (Did you mean: {', '.join(possible_values)})" |
| 397 | + if possible_options: |
| 398 | + message += f" (Did you mean: {', '.join(possible_options.keys())})" |
389 | 399 |
|
390 | 400 | raise BadArgumentError( |
391 | 401 | message, value=raw.name, command=parse_state.current_command |
|
0 commit comments