summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-13 23:33:58 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-03-13 23:33:58 -0400
commit88b45e12b0c2c9e7f8e386504f2d6808f396560b (patch)
tree66209a092dc11528f73a9cb1a991c620be09a815 /examples
parent23fad46d5187600d52b95125bb1629e491cb9e6f (diff)
downloadcmd2-git-88b45e12b0c2c9e7f8e386504f2d6808f396560b.tar.gz
First stage of attribute refactoring
The following are now arguments to cmd2.Cmd.__init__() instead of class attributes: * allow_redirection * multiline_commands * terminators * shortcuts Added a couple read-only properties for convenience of cmd2.Cmd accessing immutable members from self.statement_parser
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/arg_print.py2
-rwxr-xr-xexamples/cmd_as_argument.py3
-rwxr-xr-xexamples/colors.py3
-rwxr-xr-xexamples/decorator_example.py3
-rwxr-xr-xexamples/example.py3
-rwxr-xr-xexamples/pirate.py5
-rwxr-xr-xexamples/plumbum_colors.py3
7 files changed, 8 insertions, 14 deletions
diff --git a/examples/arg_print.py b/examples/arg_print.py
index 18d21787..a7b938e3 100755
--- a/examples/arg_print.py
+++ b/examples/arg_print.py
@@ -24,7 +24,7 @@ class ArgumentAndOptionPrinter(cmd2.Cmd):
# 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, multiline_commands, etc.
+ # are not settable at runtime. This includes the shortcuts, etc.
def do_aprint(self, statement):
"""Print the argument string this basic command is called with."""
diff --git a/examples/cmd_as_argument.py b/examples/cmd_as_argument.py
index dcec81c8..48397a42 100755
--- a/examples/cmd_as_argument.py
+++ b/examples/cmd_as_argument.py
@@ -30,14 +30,13 @@ class CmdLineApp(cmd2.Cmd):
def __init__(self):
self.allow_cli_args = False
- self.multiline_commands = ['orate']
self.maxrepeats = 3
# Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=False)
+ super().__init__(use_ipython=False, multiline_commands=['orate'])
# Make maxrepeats settable at runtime
self.settable['maxrepeats'] = 'max repetitions for speak command'
diff --git a/examples/colors.py b/examples/colors.py
index 62df54e6..6f4912be 100755
--- a/examples/colors.py
+++ b/examples/colors.py
@@ -63,14 +63,13 @@ class CmdLineApp(cmd2.Cmd):
MUMBLE_LAST = ['right?']
def __init__(self):
- self.multiline_commands = ['orate']
self.maxrepeats = 3
# Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=True)
+ super().__init__(use_ipython=True, multiline_commands=['orate'])
# 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 5d127619..873d37cd 100755
--- a/examples/decorator_example.py
+++ b/examples/decorator_example.py
@@ -19,12 +19,11 @@ import cmd2
class CmdLineApp(cmd2.Cmd):
""" Example cmd2 application. """
def __init__(self, ip_addr=None, port=None, transcript_files=None):
- self.multiline_commands = ['orate']
self.shortcuts.update({'&': 'speak'})
self.maxrepeats = 3
# 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)
+ super().__init__(use_ipython=False, transcript_files=transcript_files, multiline_commands=['orate'])
# 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 04727ec6..145ddb79 100755
--- a/examples/example.py
+++ b/examples/example.py
@@ -27,14 +27,13 @@ class CmdLineApp(cmd2.Cmd):
MUMBLE_LAST = ['right?']
def __init__(self):
- self.multiline_commands = ['orate']
self.maxrepeats = 3
# Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=False)
+ super().__init__(use_ipython=False, multiline_commands=['orate'])
# Make maxrepeats settable at runtime
self.settable['maxrepeats'] = 'max repetitions for speak command'
diff --git a/examples/pirate.py b/examples/pirate.py
index 32330404..a58f9a46 100755
--- a/examples/pirate.py
+++ b/examples/pirate.py
@@ -11,6 +11,7 @@ import argparse
from colorama import Fore
import cmd2
+from cmd2.constants import MULTILINE_TERMINATOR
COLORS = {
'black': Fore.BLACK,
@@ -28,15 +29,13 @@ class Pirate(cmd2.Cmd):
"""A piratical example cmd2 application involving looting and drinking."""
def __init__(self):
self.default_to_shell = True
- self.multiline_commands = ['sing']
- self.terminators = self.terminators + ['...']
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__()
+ 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 3e5031d7..3867081b 100755
--- a/examples/plumbum_colors.py
+++ b/examples/plumbum_colors.py
@@ -66,14 +66,13 @@ class CmdLineApp(cmd2.Cmd):
MUMBLE_LAST = ['right?']
def __init__(self):
- self.multiline_commands = ['orate']
self.maxrepeats = 3
# Add stuff to shortcuts before calling base class initializer
self.shortcuts.update({'&': 'speak'})
# Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell
- super().__init__(use_ipython=True)
+ super().__init__(use_ipython=True, multiline_commands=['orate'])
# Make maxrepeats settable at runtime
self.settable['maxrepeats'] = 'max repetitions for speak command'