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

Method attach_subcommand

cmd2/cmd2.py:1199–1220  ·  view source on GitHub ↗

Attach a parser as a subcommand to a command at the specified path. :param command: full command path (space-delimited) leading to the parser that will host the new subcommand (e.g. 'foo bar') :param subcommand: name of the new subcommand :param subco

(
        self,
        command: str,
        subcommand: str,
        subcommand_parser: Cmd2ArgumentParser,
        **add_parser_kwargs: Any,
    )

Source from the content-addressed store, hash-verified

1197 return root_parser, subcommand_path
1198
1199 def attach_subcommand(
1200 self,
1201 command: str,
1202 subcommand: str,
1203 subcommand_parser: Cmd2ArgumentParser,
1204 **add_parser_kwargs: Any,
1205 ) -> None:
1206 """Attach a parser as a subcommand to a command at the specified path.
1207
1208 :param command: full command path (space-delimited) leading to the parser that will
1209 host the new subcommand (e.g. 'foo bar')
1210 :param subcommand: name of the new subcommand
1211 :param subcommand_parser: the parser to attach
1212 :param add_parser_kwargs: additional arguments for the subparser registration (e.g. help, aliases)
1213 :raises TypeError: if subcommand_parser is not an instance of the following or their subclasses:
1214 1. Cmd2ArgumentParser
1215 2. The parser_class configured for the target subcommand group
1216 :raises ValueError: if the command path is invalid, doesn't support subcommands, or the
1217 subcommand already exists
1218 """
1219 root_parser, subcommand_path = self.get_root_parser_and_subcmd_path(command)
1220 root_parser.attach_subcommand(subcommand_path, subcommand, subcommand_parser, **add_parser_kwargs)
1221
1222 def detach_subcommand(self, command: str, subcommand: str) -> Cmd2ArgumentParser:
1223 """Detach a subcommand from a command at the specified path.

Callers 3

_register_subcommandsMethod · 0.95

Calls 1

Tested by 2