diff options
-rwxr-xr-x | examples/arg_print.py | 9 | ||||
-rwxr-xr-x | examples/async_printing.py | 1 | ||||
-rwxr-xr-x | examples/cmd_as_argument.py | 12 | ||||
-rwxr-xr-x | examples/colors.py | 10 | ||||
-rwxr-xr-x | examples/decorator_example.py | 9 | ||||
-rwxr-xr-x | examples/example.py | 10 | ||||
-rwxr-xr-x | examples/pirate.py | 11 | ||||
-rwxr-xr-x | examples/plumbum_colors.py | 10 |
8 files changed, 30 insertions, 42 deletions
diff --git a/examples/arg_print.py b/examples/arg_print.py index a7b938e3..edcc8444 100755 --- a/examples/arg_print.py +++ b/examples/arg_print.py @@ -19,12 +19,9 @@ class ArgumentAndOptionPrinter(cmd2.Cmd): def __init__(self): # Create command shortcuts which are typically 1 character abbreviations which can be used in place of a command - self.shortcuts.update({'$': 'aprint', '%': 'oprint'}) - - # Make sure to call this super class __init__ *after* setting and/or updating shortcuts - super().__init__() - # NOTE: It is critical that the super class __init__ method be called AFTER updating certain parameters which - # are not settable at runtime. This includes the shortcuts, etc. + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'$': 'aprint', '%': 'oprint'}) + super().__init__(shortcuts=shortcuts) def do_aprint(self, statement): """Print the argument string this basic command is called with.""" diff --git a/examples/async_printing.py b/examples/async_printing.py index dddbc352..60119a9c 100755 --- a/examples/async_printing.py +++ b/examples/async_printing.py @@ -32,7 +32,6 @@ class AlerterApp(cmd2.Cmd): def __init__(self, *args, **kwargs) -> None: """ Initializer """ - super().__init__(*args, **kwargs) self.prompt = "(APR)> " diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py index 48397a42..df7e1d76 100755 --- a/examples/cmd_as_argument.py +++ b/examples/cmd_as_argument.py @@ -29,15 +29,13 @@ class CmdLineApp(cmd2.Cmd): MUMBLE_LAST = ['right?'] def __init__(self): - self.allow_cli_args = False - self.maxrepeats = 3 - - # Add stuff to shortcuts before calling base class initializer - self.shortcuts.update({'&': 'speak'}) - + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'&': 'speak'}) # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell - super().__init__(use_ipython=False, multiline_commands=['orate']) + super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts) + self.allow_cli_args = False + self.maxrepeats = 3 # Make maxrepeats settable at runtime self.settable['maxrepeats'] = 'max repetitions for speak command' diff --git a/examples/colors.py b/examples/colors.py index 6f4912be..ea0bca39 100755 --- a/examples/colors.py +++ b/examples/colors.py @@ -63,14 +63,12 @@ class CmdLineApp(cmd2.Cmd): MUMBLE_LAST = ['right?'] def __init__(self): - self.maxrepeats = 3 - - # Add stuff to shortcuts before calling base class initializer - self.shortcuts.update({'&': 'speak'}) - + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'&': 'speak'}) # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell - super().__init__(use_ipython=True, multiline_commands=['orate']) + super().__init__(use_ipython=True, multiline_commands=['orate'], shortcuts=shortcuts) + self.maxrepeats = 3 # Make maxrepeats settable at runtime self.settable['maxrepeats'] = 'max repetitions for speak command' diff --git a/examples/decorator_example.py b/examples/decorator_example.py index 873d37cd..cf948d1d 100755 --- a/examples/decorator_example.py +++ b/examples/decorator_example.py @@ -19,12 +19,13 @@ import cmd2 class CmdLineApp(cmd2.Cmd): """ Example cmd2 application. """ def __init__(self, ip_addr=None, port=None, transcript_files=None): - self.shortcuts.update({'&': 'speak'}) - self.maxrepeats = 3 - + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'&': 'speak'}) # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell - super().__init__(use_ipython=False, transcript_files=transcript_files, multiline_commands=['orate']) + super().__init__(use_ipython=False, transcript_files=transcript_files, multiline_commands=['orate'], + shortcuts=shortcuts) + self.maxrepeats = 3 # Make maxrepeats settable at runtime self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed' diff --git a/examples/example.py b/examples/example.py index 145ddb79..9f9c0304 100755 --- a/examples/example.py +++ b/examples/example.py @@ -27,15 +27,13 @@ class CmdLineApp(cmd2.Cmd): MUMBLE_LAST = ['right?'] def __init__(self): - self.maxrepeats = 3 - - # Add stuff to shortcuts before calling base class initializer - self.shortcuts.update({'&': 'speak'}) - + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'&': 'speak'}) # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell - super().__init__(use_ipython=False, multiline_commands=['orate']) + super().__init__(use_ipython=False, multiline_commands=['orate'], shortcuts=shortcuts) # Make maxrepeats settable at runtime + self.maxrepeats = 3 self.settable['maxrepeats'] = 'max repetitions for speak command' speak_parser = argparse.ArgumentParser() diff --git a/examples/pirate.py b/examples/pirate.py index a58f9a46..994ca245 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -28,15 +28,14 @@ COLORS = { class Pirate(cmd2.Cmd): """A piratical example cmd2 application involving looting and drinking.""" def __init__(self): + """Initialize the base class as well as this one""" + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'~': 'sing'}) + super().__init__(multiline_commands=['sing'], terminators=[MULTILINE_TERMINATOR, '...'], shortcuts=shortcuts) + self.default_to_shell = True self.songcolor = Fore.BLUE - # Add stuff to shortcuts before calling base class initializer - self.shortcuts.update({'~': 'sing'}) - - """Initialize the base class as well as this one""" - super().__init__(multiline_commands=['sing'], terminators=[MULTILINE_TERMINATOR, '...']) - # Make songcolor settable at runtime self.settable['songcolor'] = 'Color to ``sing`` in (black/red/green/yellow/blue/magenta/cyan/white)' diff --git a/examples/plumbum_colors.py b/examples/plumbum_colors.py index 3867081b..6daa5312 100755 --- a/examples/plumbum_colors.py +++ b/examples/plumbum_colors.py @@ -66,14 +66,12 @@ class CmdLineApp(cmd2.Cmd): MUMBLE_LAST = ['right?'] def __init__(self): - self.maxrepeats = 3 - - # Add stuff to shortcuts before calling base class initializer - self.shortcuts.update({'&': 'speak'}) - + shortcuts = dict(self.DEFAULT_SHORTCUTS) + shortcuts.update({'&': 'speak'}) # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell - super().__init__(use_ipython=True, multiline_commands=['orate']) + super().__init__(use_ipython=True, multiline_commands=['orate'], shortcuts=shortcuts) + self.maxrepeats = 3 # Make maxrepeats settable at runtime self.settable['maxrepeats'] = 'max repetitions for speak command' |