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_commands | |
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_commands')
-rw-r--r-- | examples/modular_commands/commandset_basic.py | 10 | ||||
-rw-r--r-- | examples/modular_commands/commandset_complex.py | 32 | ||||
-rw-r--r-- | examples/modular_commands/commandset_custominit.py | 4 |
3 files changed, 23 insertions, 23 deletions
diff --git a/examples/modular_commands/commandset_basic.py b/examples/modular_commands/commandset_basic.py index 105530e8..2ceda439 100644 --- a/examples/modular_commands/commandset_basic.py +++ b/examples/modular_commands/commandset_basic.py @@ -30,7 +30,7 @@ class BasicCompletionCommandSet(CommandSet): -s, --sport [completes sports] -p, --path [completes local file system paths] """ - cmd.poutput("Args: {}".format(statement.args)) + self._cmd.poutput("Args: {}".format(statement.args)) def complete_flag_based(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]: """Completion function for do_flag_based""" @@ -53,7 +53,7 @@ class BasicCompletionCommandSet(CommandSet): def do_index_based(self, cmd: Cmd, statement: Statement): """Tab completes first 3 arguments using index_based_complete""" - cmd.poutput("Args: {}".format(statement.args)) + self._cmd.poutput("Args: {}".format(statement.args)) def complete_index_based(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]: """Completion function for do_index_based""" @@ -68,14 +68,14 @@ class BasicCompletionCommandSet(CommandSet): def do_delimiter_complete(self, cmd: Cmd, statement: Statement): """Tab completes files from a list using delimiter_complete""" - cmd.poutput("Args: {}".format(statement.args)) + self._cmd.poutput("Args: {}".format(statement.args)) def complete_delimiter_complete(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]: return cmd.delimiter_complete(text, line, begidx, endidx, match_against=self.file_strs, delimiter='/') def do_raise_error(self, cmd: Cmd, statement: Statement): """Demonstrates effect of raising CompletionError""" - cmd.poutput("Args: {}".format(statement.args)) + self._cmd.poutput("Args: {}".format(statement.args)) def complete_raise_error(self, cmd: Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]: """ @@ -89,4 +89,4 @@ class BasicCompletionCommandSet(CommandSet): @with_category('Not Basic Completion') def do_custom_category(self, cmd: Cmd, statement: Statement): - cmd.poutput('Demonstrates a command that bypasses the default category') + self._cmd.poutput('Demonstrates a command that bypasses the default category') diff --git a/examples/modular_commands/commandset_complex.py b/examples/modular_commands/commandset_complex.py index ec5a9e13..7c6b1300 100644 --- a/examples/modular_commands/commandset_complex.py +++ b/examples/modular_commands/commandset_complex.py @@ -13,35 +13,35 @@ from cmd2 import utils @cmd2.with_default_category('Fruits') class CommandSetA(cmd2.CommandSet): - def do_apple(self, cmd: cmd2.Cmd, statement: cmd2.Statement): - cmd.poutput('Apple!') + def do_apple(self, statement: cmd2.Statement): + self._cmd.poutput('Apple!') - def do_banana(self, cmd: cmd2.Cmd, statement: cmd2.Statement): + def do_banana(self, statement: cmd2.Statement): """Banana Command""" - cmd.poutput('Banana!!') + self._cmd.poutput('Banana!!') cranberry_parser = cmd2.Cmd2ArgumentParser('cranberry') cranberry_parser.add_argument('arg1', choices=['lemonade', 'juice', 'sauce']) @cmd2.with_argparser(cranberry_parser, with_unknown_args=True) - def do_cranberry(self, cmd: cmd2.Cmd, ns: argparse.Namespace, unknown: List[str]): - cmd.poutput('Cranberry {}!!'.format(ns.arg1)) + def do_cranberry(self, ns: argparse.Namespace, unknown: List[str]): + self._cmd.poutput('Cranberry {}!!'.format(ns.arg1)) if unknown and len(unknown): - cmd.poutput('Unknown: ' + ', '.join(['{}']*len(unknown)).format(*unknown)) - cmd.last_result = {'arg1': ns.arg1, + self._cmd.poutput('Unknown: ' + ', '.join(['{}']*len(unknown)).format(*unknown)) + self._cmd.last_result = {'arg1': ns.arg1, 'unknown': unknown} - def help_cranberry(self, cmd: cmd2.Cmd): - cmd.stdout.write('This command does diddly squat...\n') + def help_cranberry(self): + self._cmd.stdout.write('This command does diddly squat...\n') @cmd2.with_argument_list @cmd2.with_category('Also Alone') - def do_durian(self, cmd: cmd2.Cmd, args: List[str]): + def do_durian(self, args: List[str]): """Durian Command""" - cmd.poutput('{} Arguments: '.format(len(args))) - cmd.poutput(', '.join(['{}']*len(args)).format(*args)) + self._cmd.poutput('{} Arguments: '.format(len(args))) + self._cmd.poutput(', '.join(['{}']*len(args)).format(*args)) - def complete_durian(self, cmd: cmd2.Cmd, text: str, line: str, begidx: int, endidx: int) -> List[str]: + def complete_durian(self, text: str, line: str, begidx: int, endidx: int) -> List[str]: return utils.basic_complete(text, line, begidx, endidx, ['stinks', 'smells', 'disgusting']) elderberry_parser = cmd2.Cmd2ArgumentParser('elderberry') @@ -49,5 +49,5 @@ class CommandSetA(cmd2.CommandSet): @cmd2.with_category('Alone') @cmd2.with_argparser(elderberry_parser) - def do_elderberry(self, cmd: cmd2.Cmd, ns: argparse.Namespace): - cmd.poutput('Elderberry {}!!'.format(ns.arg1)) + def do_elderberry(self, ns: argparse.Namespace): + self._cmd.poutput('Elderberry {}!!'.format(ns.arg1)) diff --git a/examples/modular_commands/commandset_custominit.py b/examples/modular_commands/commandset_custominit.py index 5a574a59..2ef94a75 100644 --- a/examples/modular_commands/commandset_custominit.py +++ b/examples/modular_commands/commandset_custominit.py @@ -14,7 +14,7 @@ class CustomInitCommandSet(CommandSet): self._arg2 = arg2 def do_show_arg1(self, cmd: Cmd, _: Statement): - cmd.poutput('Arg1: ' + self._arg1) + self._cmd.poutput('Arg1: ' + self._arg1) def do_show_arg2(self, cmd: Cmd, _: Statement): - cmd.poutput('Arg2: ' + self._arg2) + self._cmd.poutput('Arg2: ' + self._arg2) |