diff options
Diffstat (limited to 'examples/modular_subcommands.py')
-rw-r--r-- | examples/modular_subcommands.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/examples/modular_subcommands.py b/examples/modular_subcommands.py index 945fd54d..44d4edd8 100644 --- a/examples/modular_subcommands.py +++ b/examples/modular_subcommands.py @@ -20,17 +20,17 @@ class LoadableFruits(CommandSet): def __init__(self): super().__init__() - def do_apple(self, cmd: cmd2.Cmd, _: cmd2.Statement): - cmd.poutput('Apple') + def do_apple(self, _: cmd2.Statement): + self._cmd.poutput('Apple') banana_description = "Cut a banana" banana_parser = cmd2.Cmd2ArgumentParser(add_help=False, description=banana_description) banana_parser.add_argument('direction', choices=['discs', 'lengthwise']) @cmd2.as_subcommand_to('cut', 'banana', banana_parser, help=banana_description.lower()) - def cut_banana(self, cmd: cmd2.Cmd, ns: argparse.Namespace): + def cut_banana(self, ns: argparse.Namespace): """Cut banana""" - cmd.poutput('cutting banana: ' + ns.direction) + self._cmd.poutput('cutting banana: ' + ns.direction) @with_default_category('Vegetables') @@ -38,16 +38,16 @@ class LoadableVegetables(CommandSet): def __init__(self): super().__init__() - def do_arugula(self, cmd: cmd2.Cmd, _: cmd2.Statement): - cmd.poutput('Arugula') + def do_arugula(self, _: cmd2.Statement): + self._cmd.poutput('Arugula') bokchoy_description = "Cut some bokchoy" bokchoy_parser = cmd2.Cmd2ArgumentParser(add_help=False, description=bokchoy_description) bokchoy_parser.add_argument('style', choices=['quartered', 'diced']) @cmd2.as_subcommand_to('cut', 'bokchoy', bokchoy_parser, help=bokchoy_description.lower()) - def cut_bokchoy(self, cmd: cmd2.Cmd, _: cmd2.Statement): - cmd.poutput('Bok Choy') + def cut_bokchoy(self, _: cmd2.Statement): + self._cmd.poutput('Bok Choy') class ExampleApp(cmd2.Cmd): @@ -70,14 +70,14 @@ class ExampleApp(cmd2.Cmd): def do_load(self, ns: argparse.Namespace): if ns.cmds == 'fruits': try: - self.install_command_set(self._fruits) + self.register_command_set(self._fruits) self.poutput('Fruits loaded') except ValueError: self.poutput('Fruits already loaded') if ns.cmds == 'vegetables': try: - self.install_command_set(self._vegetables) + self.register_command_set(self._vegetables) self.poutput('Vegetables loaded') except ValueError: self.poutput('Vegetables already loaded') @@ -85,11 +85,11 @@ class ExampleApp(cmd2.Cmd): @with_argparser(load_parser) def do_unload(self, ns: argparse.Namespace): if ns.cmds == 'fruits': - self.uninstall_command_set(self._fruits) + self.unregister_command_set(self._fruits) self.poutput('Fruits unloaded') if ns.cmds == 'vegetables': - self.uninstall_command_set(self._vegetables) + self.unregister_command_set(self._vegetables) self.poutput('Vegetables unloaded') cut_parser = cmd2.Cmd2ArgumentParser('cut') |