annotate README.txt @ 13:c6e8b645c0ab

tweaking docs
author catherine@localhost
date Thu, 15 May 2008 13:13:31 -0400
parents 47af95ad83c7
children 0a316420636e
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
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
50 @options([make_option('-m', '--myoption', action="store_true", help="atinLay")])
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
51 def myfunc(self, arg):
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
52 ...
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
53
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
54 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
55
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
56 - Catherine Devlin, catherinedevlin.blogspot.com
71067a445663 added README
catherine@localhost
parents:
diff changeset
57
71067a445663 added README
catherine@localhost
parents:
diff changeset
58 cmd2 can be installed with `easy_install cmd2`
71067a445663 added README
catherine@localhost
parents:
diff changeset
59
71067a445663 added README
catherine@localhost
parents:
diff changeset
60 Cheese Shop page: http://pypi.python.org/pypi/cmd2/0.1
71067a445663 added README
catherine@localhost
parents:
diff changeset
61
71067a445663 added README
catherine@localhost
parents:
diff changeset
62 Example cmd2 application (cmd2_example.py) ::
71067a445663 added README
catherine@localhost
parents:
diff changeset
63
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
64 from cmd2 import Cmd, make_option, options
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
65
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
66 class CmdLineApp(Cmd):
71067a445663 added README
catherine@localhost
parents:
diff changeset
67 multilineCommands = ['orate']
71067a445663 added README
catherine@localhost
parents:
diff changeset
68 Cmd.shortcuts.update({'&': 'speak'})
71067a445663 added README
catherine@localhost
parents:
diff changeset
69 maxrepeats = 3
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
70 Cmd.settable.append('maxrepeats')
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
71
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
72 @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"),
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
73 make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"),
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
74 make_option('-r', '--repeat', type="int", help="output [n] times")
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
75 ])
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
76 def do_speak(self, arg, opts=None):
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
77 """Repeats what you tell me to."""
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
78 arg = ' '.join(arg)
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
79 if opts.piglatin:
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
80 arg = '%s%say' % (arg[1:], arg[0])
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
81 if opts.shout:
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
82 arg = arg.upper()
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
83 repetitions = opts.repeat or 1
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
84 for i in range(min(repetitions, self.maxrepeats)):
71067a445663 added README
catherine@localhost
parents:
diff changeset
85 self.stdout.write(arg)
71067a445663 added README
catherine@localhost
parents:
diff changeset
86 self.stdout.write('\n')
71067a445663 added README
catherine@localhost
parents:
diff changeset
87 # self.stdout.write is better than "print", because Cmd can be
71067a445663 added README
catherine@localhost
parents:
diff changeset
88 # initialized with a non-standard output destination
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
89
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
90 do_say = do_speak # now "say" is a synonym for "speak"
71067a445663 added README
catherine@localhost
parents:
diff changeset
91 do_orate = do_speak # another synonym, but this one takes multi-line input
13
c6e8b645c0ab tweaking docs
catherine@localhost
parents: 10
diff changeset
92
6
71067a445663 added README
catherine@localhost
parents:
diff changeset
93 app = CmdLineApp()
71067a445663 added README
catherine@localhost
parents:
diff changeset
94 app.cmdloop()
71067a445663 added README
catherine@localhost
parents:
diff changeset
95
71067a445663 added README
catherine@localhost
parents:
diff changeset
96 Sample session using the above code ::
71067a445663 added README
catherine@localhost
parents:
diff changeset
97
71067a445663 added README
catherine@localhost
parents:
diff changeset
98 c:\cmd2>python cmd2_example.py
71067a445663 added README
catherine@localhost
parents:
diff changeset
99 (Cmd) speak softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
100 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
101 (Cmd) speak --piglatin softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
102 oftlysay
71067a445663 added README
catherine@localhost
parents:
diff changeset
103 (Cmd) speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
104 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
105 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
106 (Cmd) speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
107 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 (Cmd) show maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
111 maxrepeats: 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
112 (Cmd) set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
113 maxrepeats - was: 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
114 now: 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
115 (Cmd) speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
116 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 (Cmd) orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
122 > blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
123 > and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
124 > blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
125 >
71067a445663 added README
catherine@localhost
parents:
diff changeset
126 blah blah blah and furthermore blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
127 (Cmd) &greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
128 greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
129 (Cmd) history
71067a445663 added README
catherine@localhost
parents:
diff changeset
130 -------------------------[1]
71067a445663 added README
catherine@localhost
parents:
diff changeset
131 speak softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
132 -------------------------[2]
71067a445663 added README
catherine@localhost
parents:
diff changeset
133 speak --piglatin softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
134 -------------------------[3]
71067a445663 added README
catherine@localhost
parents:
diff changeset
135 speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
136 -------------------------[4]
71067a445663 added README
catherine@localhost
parents:
diff changeset
137 speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
138 -------------------------[5]
71067a445663 added README
catherine@localhost
parents:
diff changeset
139 show maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
140 -------------------------[6]
71067a445663 added README
catherine@localhost
parents:
diff changeset
141 set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
142 -------------------------[7]
71067a445663 added README
catherine@localhost
parents:
diff changeset
143 speak --repeat 1000000 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
144 -------------------------[8]
71067a445663 added README
catherine@localhost
parents:
diff changeset
145 orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
146 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
147 and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
148 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
149
71067a445663 added README
catherine@localhost
parents:
diff changeset
150 -------------------------[9]
71067a445663 added README
catherine@localhost
parents:
diff changeset
151 &greetings
71067a445663 added README
catherine@localhost
parents:
diff changeset
152 (Cmd) run
71067a445663 added README
catherine@localhost
parents:
diff changeset
153 orate blah blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
154 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
155 and furthermore
71067a445663 added README
catherine@localhost
parents:
diff changeset
156 blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
157
71067a445663 added README
catherine@localhost
parents:
diff changeset
158 blah blah blah and furthermore blah
71067a445663 added README
catherine@localhost
parents:
diff changeset
159 (Cmd) run 3
71067a445663 added README
catherine@localhost
parents:
diff changeset
160 speak -psr 2 softly
71067a445663 added README
catherine@localhost
parents:
diff changeset
161 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
162 OFTLYSAY
71067a445663 added README
catherine@localhost
parents:
diff changeset
163 (Cmd) history maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
164 -------------------------[5]
71067a445663 added README
catherine@localhost
parents:
diff changeset
165 set maxrepeats
71067a445663 added README
catherine@localhost
parents:
diff changeset
166 -------------------------[6]
71067a445663 added README
catherine@localhost
parents:
diff changeset
167 set maxrepeats 5
71067a445663 added README
catherine@localhost
parents:
diff changeset
168 (Cmd)