diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2016-12-09 16:54:10 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2016-12-09 16:54:10 -0500 |
commit | 06331d3ab75feb807dc48d824cbd54898a6b6cdd (patch) | |
tree | 24034e3f0ff7cd94239d575fe046acc550e7a49f /README.rst | |
parent | b9658cff197beff5a00632a68ecf85838879835e (diff) | |
download | cmd2-git-06331d3ab75feb807dc48d824cbd54898a6b6cdd.tar.gz |
First stage of refactoring to support full simultaneous Python 2 and 3 compatibility via use of the six module.
Diffstat (limited to 'README.rst')
-rwxr-xr-x | README.rst | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -40,8 +40,8 @@ Instructions for implementing each feature follow. - Searchable command history
- All commands will automatically be tracked in the session's history, unless the command is listed in Cmd's excludeFromHistory attribute.
- The history is accessed through the `history`, `list`, and `run` commands
+ All commands will automatically be tracked in the session's history, unless the command is listed in Cmd's excludeFromHistory attribute.
+ The history is accessed through the `history`, `list`, and `run` commands
(and their abbreviations: `hi`, `li`, `l`, `r`).
If you wish to exclude some of your custom commands from the history, append their names
to the list at Cmd.ExcludeFromHistory.
@@ -49,37 +49,37 @@ Instructions for implementing each feature follow. - Load commands from file, save to file, edit commands in file
Type `help load`, `help save`, `help edit` for details.
-
+
- Multi-line commands
Any command accepts multi-line input when its name is listed in `Cmd.multilineCommands`.
- The program will keep expecting input until a line ends with any of the characters
+ The program will keep expecting input until a line ends with any of the characters
in `Cmd.terminators` . The default terminators are `;` and `/n` (empty newline).
-
+
- Case-insensitive commands
All commands are case-insensitive, unless `Cmd.caseInsensitive` is set to `False`.
-
+
- Special-character shortcut commands (beyond cmd's "@" and "!")
To create a single-character shortcut for a command, update `Cmd.shortcuts`.
-
+
- Settable environment parameters
- To allow a user to change an environment parameter during program execution,
+ To allow a user to change an environment parameter during program execution,
append the parameter's name to `Cmd.settable`.
-
-- Parsing commands with `optparse` options (flags)
+
+- Parsing commands with `optparse` options (flags)
::
-
+
@options([make_option('-m', '--myoption', action="store_true", help="all about my option")])
def do_myfunc(self, arg, opts):
if opts.myoption:
...
-
+
See Python standard library's `optparse` documentation: http://docs.python.org/lib/optparse-defining-options.html
-
+
cmd2 can be installed with `easy_install cmd2`
Cheese Shop page: http://pypi.python.org/pypi/cmd2
@@ -87,16 +87,16 @@ Cheese Shop page: http://pypi.python.org/pypi/cmd2 Example cmd2 application (example/example.py) ::
'''A sample application for cmd2.'''
-
+
from cmd2 import Cmd, make_option, options, Cmd2TestCase
import unittest, optparse, sys
-
+
class CmdLineApp(Cmd):
multilineCommands = ['orate']
Cmd.shortcuts.update({'&': 'speak'})
maxrepeats = 3
Cmd.settable.append('maxrepeats')
-
+
@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")
@@ -114,14 +114,14 @@ Example cmd2 application (example/example.py) :: self.stdout.write('\n')
# self.stdout.write is better than "print", because Cmd can be
# initialized with a non-standard output destination
-
+
do_say = do_speak # now "say" is a synonym for "speak"
do_orate = do_speak # another synonym, but this one takes multi-line input
-
+
class TestMyAppCase(Cmd2TestCase):
CmdApp = CmdLineApp
transcriptFileName = 'exampleSession.txt'
-
+
parser = optparse.OptionParser()
parser.add_option('-t', '--test', dest='unittests', action='store_true', default=False, help='Run unit test suite')
(callopts, callargs) = parser.parse_args()
@@ -133,8 +133,8 @@ Example cmd2 application (example/example.py) :: app.cmdloop()
The following is a sample session running example.py.
-Thanks to `TestMyAppCase(Cmd2TestCase)`, it also serves as a test
-suite for example.py when saved as `exampleSession.txt`.
+Thanks to `TestMyAppCase(Cmd2TestCase)`, it also serves as a test
+suite for example.py when saved as `exampleSession.txt`.
Running `python example.py -t` will run all the commands in the
transcript against `example.py`, verifying that the output produced
matches the transcript.
@@ -142,12 +142,12 @@ matches the transcript. example/exampleSession.txt::
(Cmd) help
-
+
Documented commands (type help <topic>):
========================================
- _load edit history li load pause run say shell show
+ _load edit history li load pause run say shell show
ed hi l list orate r save set shortcuts speak
-
+
Undocumented commands:
======================
EOF cmdenvironment eof exit help q quit
@@ -155,14 +155,14 @@ example/exampleSession.txt:: (Cmd) help say
Repeats what you tell me to.
Usage: speak [options] arg
-
+
Options:
-h, --help show this help message and exit
-p, --piglatin atinLay
-s, --shout N00B EMULATION MODE
-r REPEAT, --repeat=REPEAT
output [n] times
-
+
(Cmd) say goodnight, Gracie
goodnight, Gracie
(Cmd) say -ps --repeat=5 goodnight, Gracie
@@ -222,3 +222,4 @@ example/exampleSession.txt:: now: --->
---> say goodbye
goodbye
+
|