diff options
author | Eric Lin <anselor@gmail.com> | 2020-08-12 13:08:59 -0400 |
---|---|---|
committer | anselor <anselor@gmail.com> | 2020-08-12 17:41:20 -0400 |
commit | 774fb39d7e259d0679c573b0d893293f9ed9aed9 (patch) | |
tree | a78a4693e7cca707668eb89b0d8e41c3fedd108e /examples/modular_subcommands.py | |
parent | 4d628ea7573ef9016971dbbf7de9126c6d179227 (diff) | |
download | cmd2-git-774fb39d7e259d0679c573b0d893293f9ed9aed9.tar.gz |
Breaking change: Removed cmd2 app as a required second parameter to
CommandSet command functions (do_, complete_, help_).
Renamed install_command_set and uninstall_command_set to
register_command_set and unregister_command_set.
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') |