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

Method detach_subcommand

cmd2/argparse_utils.py:832–850  ·  view source on GitHub ↗

Detach a subcommand from a command at the specified path. :param subcommand_path: sequence of subcommand names leading to the parser hosting the subcommand to be detached. An empty sequence indicates this parser. :param subcommand: name of the subcomm

(self, subcommand_path: Iterable[str], subcommand: str)

Source from the content-addressed store, hash-verified

830 subparsers_action._name_parser_map[alias] = subcommand_parser
831
832 def detach_subcommand(self, subcommand_path: Iterable[str], subcommand: str) -> "Cmd2ArgumentParser":
833 """Detach a subcommand from a command at the specified path.
834
835 :param subcommand_path: sequence of subcommand names leading to the parser hosting the
836 subcommand to be detached. An empty sequence indicates this parser.
837 :param subcommand: name of the subcommand to detach
838 :return: the detached parser
839 :raises ValueError: if the command path is invalid or the subcommand doesn't exist
840 """
841 target_parser = self.find_parser(subcommand_path)
842 subparsers_action = target_parser.get_subparsers_action()
843
844 try:
845 return cast(
846 Cmd2ArgumentParser,
847 subparsers_action.remove_parser(subcommand), # type: ignore[attr-defined]
848 )
849 except ValueError:
850 raise ValueError(f"Subcommand '{subcommand}' does not exist for '{target_parser.prog}'") from None
851
852 def error(self, message: str) -> NoReturn:
853 """Override that applies custom formatting to the error message."""

Calls 2

find_parserMethod · 0.95
get_subparsers_actionMethod · 0.80