diff options
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/argparse_example.py | 20 | ||||
-rwxr-xr-x | examples/example.py | 1 | ||||
-rwxr-xr-x | examples/pirate.py | 16 | ||||
-rw-r--r-- | examples/transcript_regex.txt | 3 |
4 files changed, 22 insertions, 18 deletions
diff --git a/examples/argparse_example.py b/examples/argparse_example.py index c6cc819b..1358559c 100755 --- a/examples/argparse_example.py +++ b/examples/argparse_example.py @@ -3,10 +3,10 @@ """A sample application for cmd2 showing how to use Argparse to process command line arguments for your application. It doubles as an example of how you can still do transcript testing even if allow_cli_args is false. -Thanks to cmd2's built-in transcript testing capability, it also serves as a test suite for argparse_example.py when +Thanks to cmd2's built-in transcript testing capability, it also serves as a test suite for argparse_example.py when used with the exampleSession.txt transcript. -Running `python argparse_example.py -t exampleSession.txt` will run all the commands in the transcript against +Running `python argparse_example.py -t exampleSession.txt` will run all the commands in the transcript against argparse_example.py, verifying that the output produced matches the transcript. """ import argparse @@ -16,15 +16,14 @@ from cmd2 import Cmd, make_option, options class CmdLineApp(Cmd): """ Example cmd2 application. """ - multilineCommands = ['orate'] - Cmd.shortcuts.update({'&': 'speak'}) - maxrepeats = 3 - Cmd.settable.append('maxrepeats') + def __init__(self, ip_addr=None, port=None, transcript_files=None): + self.multilineCommands = ['orate'] + self.shortcuts.update({'&': 'speak'}) + self.maxrepeats = 3 - # Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist - # default_to_shell = True + # Add stuff to settable and/or shortcuts before calling base class initializer + self.settable['maxrepeats'] = 'Max number of `--repeat`s allowed' - def __init__(self, ip_addr=None, port=None, transcript_files=None): # Set use_ipython to True to enable the "ipy" command which embeds and interactive IPython shell Cmd.__init__(self, use_ipython=False, transcript_files=transcript_files) @@ -35,6 +34,9 @@ class CmdLineApp(Cmd): self._ip = ip_addr self._port = port + # Setting this true makes it run a shell command if a cmd2/cmd command doesn't exist + # self.default_to_shell = True + @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"), make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"), make_option('-r', '--repeat', type="int", help="output [n] times") diff --git a/examples/example.py b/examples/example.py index fd886a76..482788cc 100755 --- a/examples/example.py +++ b/examples/example.py @@ -19,6 +19,7 @@ class CmdLineApp(Cmd): # default_to_shell = True def __init__(self): + self.abbrev = True self.multilineCommands = ['orate'] self.maxrepeats = 3 diff --git a/examples/pirate.py b/examples/pirate.py index 4fd7e6be..32d7769e 100755 --- a/examples/pirate.py +++ b/examples/pirate.py @@ -11,14 +11,16 @@ from cmd2 import Cmd, options, make_option class Pirate(Cmd): """A piratical example cmd2 application involving looting and drinking.""" - default_to_shell = True - multilineCommands = ['sing'] - terminators = Cmd.terminators + ['...'] - songcolor = 'blue' - settable = Cmd.settable + 'songcolor Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)' - Cmd.shortcuts.update({'~': 'sing'}) - def __init__(self): + self.default_to_shell = True + self.multilineCommands = ['sing'] + self.terminators = Cmd.terminators + ['...'] + self.songcolor = 'blue' + + # Add stuff to settable and/or shortcuts before calling base class initializer + self.settable['songcolor'] = 'Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)' + self.shortcuts.update({'~': 'sing'}) + """Initialize the base class as well as this one""" Cmd.__init__(self) # prompts and defaults diff --git a/examples/transcript_regex.txt b/examples/transcript_regex.txt index 61bd8838..47357284 100644 --- a/examples/transcript_regex.txt +++ b/examples/transcript_regex.txt @@ -3,13 +3,12 @@ (Cmd) set abbrev: True autorun_on_edit: False -case_insensitive: True colors: /(True|False)/ continuation_prompt: > debug: False echo: False editor: /([^\s]+)/ -feedback_to_output: False +feedback_to_output: True locals_in_py: True maxrepeats: 3 prompt: (Cmd) |