annotate README.txt @ 18:b7489d3f838e

more readme correction, now in function def
author catherine@localhost
date Thu, 15 May 2008 13:43:54 -0400
parents f81b5670a713
children 1899088dd95d
rev   line source
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
1 `cmd2` is a tool for writing command-line interactive applications. It is based on the Python Standard Library's `cmd` module, and can be used anyplace `cmd` is used simply by importing `cmd2` instead.
71067a445663 added README
catherine@localhost
parents:
diff changeset
2
71067a445663 added README
catherine@localhost
parents:
diff changeset
3 `cmd2` provides the following features, in addition to those already existing in `cmd`:
71067a445663 added README
catherine@localhost
parents:
diff changeset
4
71067a445663 added README
catherine@localhost
parents:
diff changeset
5 - Searchable command history
71067a445663 added README
catherine@localhost
parents:
diff changeset
6 - Load commands from file, save to file, edit commands in file
71067a445663 added README
catherine@localhost
parents:
diff changeset
7 - Multi-line commands
71067a445663 added README
catherine@localhost
parents:
diff changeset
8 - Case-insensitive commands
71067a445663 added README
catherine@localhost
parents:
diff changeset
9 - Special-character shortcut commands (beyond cmd's "@" and "!")
71067a445663 added README
catherine@localhost
parents:
diff changeset
10 - Settable environment parameters
71067a445663 added README
catherine@localhost
parents:
diff changeset
11 - Parsing commands with flags
71067a445663 added README
catherine@localhost
parents:
diff changeset
12
71067a445663 added README
catherine@localhost
parents:
diff changeset
13 Instructions for implementing each feature follow.
71067a445663 added README
catherine@localhost
parents:
diff changeset
14
71067a445663 added README
catherine@localhost
parents:
diff changeset
15 - Searchable command history
71067a445663 added README
catherine@localhost
parents:
diff changeset
16
71067a445663 added README
catherine@localhost
parents:
diff changeset
17 All commands will automatically be tracked in the session's history, unless the command is listed in Cmd's excludeFromHistory attribute.
71067a445663 added README
catherine@localhost
parents:
diff changeset
18 The history is accessed through the `history`, `list`, and `run` commands
71067a445663 added README
catherine@localhost
parents:
diff changeset
19 (and their abbreviations: `hi`, `li`, `l`, `r`).
71067a445663 added README
catherine@localhost
parents:
diff changeset
20 If you wish to exclude some of your custom commands from the history, append their names
71067a445663 added README
catherine@localhost
parents:
diff changeset
21 to the list at Cmd.ExcludeFromHistory.
71067a445663 added README
catherine@localhost
parents:
diff changeset
22
71067a445663 added README
catherine@localhost
parents:
diff changeset
23 - Load commands from file, save to file, edit commands in file
71067a445663 added README
catherine@localhost
parents:
diff changeset
24
71067a445663 added README
catherine@localhost
parents:
diff changeset
25 Type `help load`, `help save`, `help edit` for details.
71067a445663 added README
catherine@localhost
parents:
diff changeset
26
71067a445663 added README
catherine@localhost
parents:
diff changeset
27 - Multi-line commands
71067a445663 added README
catherine@localhost
parents:
diff changeset
28
71067a445663 added README
catherine@localhost
parents:
diff changeset
29 Any command accepts multi-line input when its name is listed in `Cmd.multilineCommands`.
71067a445663 added README
catherine@localhost
parents:
diff changeset
30 The program will keep expecting input until a line ends with any of the characters
71067a445663 added README
catherine@localhost
parents:
diff changeset
31 in `Cmd.terminators` . The default terminators are `;` and `/n` (empty newline).
71067a445663 added README
catherine@localhost
parents:
diff changeset
32
71067a445663 added README
catherine@localhost
parents:
diff changeset
33 - Case-insensitive commands
71067a445663 added README
catherine@localhost
parents:
diff changeset
34
71067a445663 added README
catherine@localhost
parents:
diff changeset
35 All commands are case-insensitive, unless `Cmd.caseInsensitive` is set to `False`.
71067a445663 added README
catherine@localhost
parents:
diff changeset
36
71067a445663 added README
catherine@localhost
parents:
diff changeset
37 - Special-character shortcut commands (beyond cmd's "@" and "!")
71067a445663 added README
catherine@localhost
parents:
diff changeset
38
71067a445663 added README
catherine@localhost
parents:
diff changeset
39 To create a single-character shortcut for a command, update `Cmd.shortcuts`.
71067a445663 added README
catherine@localhost
parents:
diff changeset
40
71067a445663 added README
catherine@localhost
parents:
diff changeset
41 - Settable environment parameters
71067a445663 added README
catherine@localhost
parents:
diff changeset
42
71067a445663 added README
catherine@localhost
parents:
diff changeset
43 To allow a user to change an environment parameter during program execution,
71067a445663 added README
catherine@localhost
parents:
diff changeset
44 append the parameter's name to `Cmd.settable`.
71067a445663 added README
catherine@localhost
parents:
diff changeset
45
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
46 - Parsing commands with `optparse` options (flags)
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
47
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
48 ::
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
49
17
f81b5670a713 more readme connection
catherine@localhost
parents: 16
diff changeset
50 @options([make_option('-m', '--myoption', action="store_true", help="all about my option")])
18
b7489d3f838e more readme correction, now in function def
catherine@localhost
parents: 17
diff changeset
51 def myfunc(self, arg, opts):
b7489d3f838e more readme correction, now in function def
catherine@localhost
parents: 17
diff changeset
52 if opts.myoption:
b7489d3f838e more readme correction, now in function def
catherine@localhost
parents: 17
diff changeset
53 ...
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
54
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
55 See Python standard library's `optparse` documentation: http://docs.python.org/lib/optparse-defining-options.html
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
56
18
b7489d3f838e more readme correction, now in function def
catherine@localhost
parents: 17
diff changeset
57 - Catherine Devlin, http://catherinedevlin.blogspot.com
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
58
71067a445663 added README
catherine@localhost
parents:
diff changeset
59 cmd2 can be installed with `easy_install cmd2`
71067a445663 added README
catherine@localhost
parents:
diff changeset
60
16
0a316420636e correction in pypi page url in readme
catherine@localhost
parents: 13
diff changeset
61 Cheese Shop page: http://pypi.python.org/pypi/cmd2
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
62
71067a445663 added README
catherine@localhost
parents:
diff changeset
63 Example cmd2 application (cmd2_example.py) ::
71067a445663 added README
catherine@localhost
parents:
diff changeset
64
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
65 from cmd2 import Cmd, make_option, options
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
66
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
67 class CmdLineApp(Cmd):
71067a445663 added README
catherine@localhost
parents:
diff changeset
68 multilineCommands = ['orate']
71067a445663 added README
catherine@localhost
parents:
diff changeset
69 Cmd.shortcuts.update({'&': 'speak'})
71067a445663 added README
catherine@localhost
parents:
diff changeset
70 maxrepeats = 3
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
71 Cmd.settable.append('maxrepeats')
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
72
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
73 @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"),
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
74 make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"),
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
75 make_option('-r', '--repeat', type="int", help="output [n] times")
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
76 ])
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
77 def do_speak(self, arg, opts=None):
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
78 """Repeats what you tell me to."""
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
79 arg = ' '.join(arg)
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
80 if opts.piglatin:
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
81 arg = '%s%say' % (arg[1:], arg[0])
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
82 if opts.shout:
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
83 arg = arg.upper()
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
84 repetitions = opts.repeat or 1
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
85 for i in range(min(repetitions, self.maxrepeats)):
71067a445663 added README
catherine@localhost
parents:
diff changeset
86 self.stdout.write(arg)
71067a445663 added README
catherine@localhost
parents:
diff changeset
87 self.stdout.write('\n')
71067a445663 added README
catherine@localhost
parents:
diff changeset
88 # self.stdout.write is better than "print", because Cmd can be
71067a445663 added README
catherine@localhost
parents:
diff changeset
89 # initialized with a non-standard output destination
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
90
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
91 do_say = do_speak # now "say" is a synonym for "speak"
71067a445663 added README
catherine@localhost
parents:
diff changeset
92 do_orate = do_speak # another synonym, but this one takes multi-line input
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
93
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
94 app = CmdLineApp()
71067a445663 added README
catherine@localhost
parents:
diff changeset
95 app.cmdloop()
71067a445663 added README
catherine@localhost
parents:
diff changeset
96
71067a445663 added README
catherine@localhost
parents:
diff changeset
97 Sample session using the above code ::
71067a445663 added README
catherine@localhost
parents:
diff changeset
98
71067a445663 added README
catherine@localhost
parents:
diff changeset
99 c:\cmd2>python cmd2_example.py
71067a445663 added README
catherine@localhost
parents:
diff changeset
100 (Cmd) speak softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
101 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
102 (Cmd) speak --piglatin softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
103 oftlysay
71067a445663 added README
catherine@localhost
parents:
diff changeset
104 (Cmd) speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
105 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
106 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
107 (Cmd) speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
108 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
109 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
110 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
111 (Cmd) show maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
112 maxrepeats: 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
113 (Cmd) set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
114 maxrepeats - was: 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
115 now: 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
116 (Cmd) speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
117 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
118 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
119 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
120 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
121 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
122 (Cmd) orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
123 > blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
124 > and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
125 > blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
126 >
71067a445663 added README
catherine@localhost
parents:
diff changeset
127 blah blah blah and furthermore blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
128 (Cmd) &greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
129 greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
130 (Cmd) history
71067a445663 added README
catherine@localhost
parents:
diff changeset
131 -------------------------[1]
71067a445663 added README
catherine@localhost
parents:
diff changeset
132 speak softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
133 -------------------------[2]
71067a445663 added README
catherine@localhost
parents:
diff changeset
134 speak --piglatin softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
135 -------------------------[3]
71067a445663 added README
catherine@localhost
parents:
diff changeset
136 speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
137 -------------------------[4]
71067a445663 added README
catherine@localhost
parents:
diff changeset
138 speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
139 -------------------------[5]
71067a445663 added README
catherine@localhost
parents:
diff changeset
140 show maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
141 -------------------------[6]
71067a445663 added README
catherine@localhost
parents:
diff changeset
142 set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
143 -------------------------[7]
71067a445663 added README
catherine@localhost
parents:
diff changeset
144 speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
145 -------------------------[8]
71067a445663 added README
catherine@localhost
parents:
diff changeset
146 orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
147 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
148 and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
149 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
150
71067a445663 added README
catherine@localhost
parents:
diff changeset
151 -------------------------[9]
71067a445663 added README
catherine@localhost
parents:
diff changeset
152 &greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
153 (Cmd) run
71067a445663 added README
catherine@localhost
parents:
diff changeset
154 orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
155 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
156 and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
157 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
158
71067a445663 added README
catherine@localhost
parents:
diff changeset
159 blah blah blah and furthermore blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
160 (Cmd) run 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
161 speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
162 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
163 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
164 (Cmd) history maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
165 -------------------------[5]
71067a445663 added README
catherine@localhost
parents:
diff changeset
166 set maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
167 -------------------------[6]
71067a445663 added README
catherine@localhost
parents:
diff changeset
168 set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
169 (Cmd)