MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / find_parser

Method find_parser

cmd2/argparse_utils.py:757–770  ·  view source on GitHub ↗

Find a parser in the hierarchy based on a sequence of subcommand names. :param subcommand_path: sequence of subcommand names leading to the target parser :return: the discovered parser :raises ValueError: if any subcommand in the path is not found or a level doesn't support

(self, subcommand_path: Iterable[str])

Source from the content-addressed store, hash-verified

755 updated_parsers.add(subcmd_parser)
756
757 def find_parser(self, subcommand_path: Iterable[str]) -> "Cmd2ArgumentParser":
758 """Find a parser in the hierarchy based on a sequence of subcommand names.
759
760 :param subcommand_path: sequence of subcommand names leading to the target parser
761 :return: the discovered parser
762 :raises ValueError: if any subcommand in the path is not found or a level doesn't support subcommands
763 """
764 parser = self
765 for name in subcommand_path:
766 subparsers_action = parser.get_subparsers_action()
767 if name not in subparsers_action._name_parser_map:
768 raise ValueError(f"Subcommand '{name}' does not exist for '{parser.prog}'")
769 parser = subparsers_action._name_parser_map[name]
770 return parser
771
772 def attach_subcommand(
773 self,

Callers 3

attach_subcommandMethod · 0.95
detach_subcommandMethod · 0.95

Calls 1

get_subparsers_actionMethod · 0.80

Tested by 1