Convert choices from action to list of CompletionItems.
(self, arg_state: _ArgumentState)
| 697 | self._parser.print_help(file) |
| 698 | |
| 699 | def _choices_to_items(self, arg_state: _ArgumentState) -> list[CompletionItem]: |
| 700 | """Convert choices from action to list of CompletionItems.""" |
| 701 | if arg_state.action.choices is None: |
| 702 | return [] |
| 703 | |
| 704 | # If choices are subcommands, then get their help text to populate display_meta. |
| 705 | if isinstance(arg_state.action, argparse._SubParsersAction): |
| 706 | parser_help = {} |
| 707 | for action in arg_state.action._choices_actions: |
| 708 | if action.dest in arg_state.action.choices: |
| 709 | subparser = arg_state.action.choices[action.dest] |
| 710 | parser_help[subparser] = action.help or "" |
| 711 | |
| 712 | return [ |
| 713 | CompletionItem(name, display_meta=parser_help.get(subparser, "")) |
| 714 | for name, subparser in arg_state.action.choices.items() |
| 715 | ] |
| 716 | |
| 717 | # Standard choices |
| 718 | return [ |
| 719 | choice if isinstance(choice, CompletionItem) else CompletionItem(choice) for choice in arg_state.action.choices |
| 720 | ] |
| 721 | |
| 722 | def _prepare_callable_params( |
| 723 | self, |
no test coverage detected