MCPcopy Create free account
hub / github.com/python-cmd2/cmd2 / _choices_to_items

Method _choices_to_items

cmd2/argparse_completer.py:699–720  ·  view source on GitHub ↗

Convert choices from action to list of CompletionItems.

(self, arg_state: _ArgumentState)

Source from the content-addressed store, hash-verified

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,

Callers 1

_complete_argMethod · 0.95

Calls 2

CompletionItemClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected