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

Method get_subparsers_action

cmd2/argparse_utils.py:660–670  ·  view source on GitHub ↗

Get the _SubParsersAction for this parser if it exists. :return: the _SubParsersAction for this parser :raises ValueError: if this parser does not support subcommands

(self)

Source from the content-addressed store, hash-verified

658 super().print_help(file)
659
660 def get_subparsers_action(self) -> "argparse._SubParsersAction[Cmd2ArgumentParser]":
661 """Get the _SubParsersAction for this parser if it exists.
662
663 :return: the _SubParsersAction for this parser
664 :raises ValueError: if this parser does not support subcommands
665 """
666 if self._subparsers is not None:
667 for action in self._subparsers._group_actions:
668 if isinstance(action, argparse._SubParsersAction):
669 return action
670 raise ValueError(f"Command '{self.prog}' does not support subcommands")
671
672 def _build_subparsers_prog_prefix(self, positionals: list[argparse.Action]) -> str:
673 """Build the 'prog' prefix for a subparsers action.

Callers 7

update_progMethod · 0.95
find_parserMethod · 0.80
attach_subcommandMethod · 0.80
detach_subcommandMethod · 0.80
get_sub_commandsFunction · 0.80

Calls

no outgoing calls

Tested by 1