annotate docs/unfreefeatures.rst @ 437:9e0fd9da25c6

Added tag 0.6.4 for changeset c4c35f002aef
author catherine.devlin@gmail.com
date Thu, 25 Aug 2011 16:27:53 -0400
parents f16f444a4d10
children
rev   line source
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
1 ======================================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
2 Features requiring application changes
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
3 ======================================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
4
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
5 Multiline commands
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
6 ==================
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
7
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
8 Command input may span multiple lines for the
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
9 commands whose names are listed in the
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
10 parameter ``app.multilineCommands``. These
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
11 commands will be executed only
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
12 after the user has entered a *terminator*.
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
13 By default, the command terminators is
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
14 ``;``; replacing or appending to the list
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
15 ``app.terminators`` allows different
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
16 terminators. A blank line
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
17 is *always* considered a command terminator
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
18 (cannot be overridden).
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
19
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
20 Parsed statements
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
21 =================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
22
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
23 ``cmd2`` passes ``arg`` to a ``do_`` method (or
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
24 ``default`) as a ParsedString, a subclass of
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
25 string that includes an attribute ``parsed``.
388
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
26 ``parsed`` is a ``pyparsing.ParseResults``
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
27 object produced by applying a pyparsing_
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
28 grammar applied to ``arg``. It may include:
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
29
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
30 command
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
31 Name of the command called
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
32
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
33 raw
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
34 Full input exactly as typed.
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
35
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
36 terminator
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
37 Character used to end a multiline command
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
38
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
39 suffix
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
40 Remnant of input after terminator
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
41
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
42 ::
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
43
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
44 def do_parsereport(self, arg):
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
45 self.stdout.write(arg.parsed.dump() + '\n')
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
46
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
47 ::
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
48
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
49 (Cmd) parsereport A B /* C */ D; E
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
50 ['parsereport', 'A B D', ';', 'E']
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
51 - args: A B D
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
52 - command: parsereport
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
53 - raw: parsereport A B /* C */ D; E
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
54 - statement: ['parsereport', 'A B D', ';']
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
55 - args: A B D
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
56 - command: parsereport
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
57 - terminator: ;
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
58 - suffix: E
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
59 - terminator: ;
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
60
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
61 If ``parsed`` does not contain an attribute,
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
62 querying for it will return ``None``. (This
388
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
63 is a characteristic of ``pyparsing.ParseResults``.)
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
64
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
65 ParsedString was developed to support sqlpython_
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
66 and reflects its needs. The parsing grammar and
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
67 process are painfully complex and should not be
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
68 considered stable; future ``cmd2`` releases may
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
69 change it somewhat (hopefully reducing complexity).
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
70
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
71 (Getting ``arg`` as a ``ParsedString`` is
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
72 technically "free", in that it requires no application
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
73 changes from the cmd_ standard, but there will
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
74 be no result unless you change your application
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
75 to *use* ``arg.parsed``.)
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
76
388
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
77 .. _sqlpython: http://pypi.python.org/pypi/sqlpython/
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
78
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
79 .. _cmd: http://docs.python.org/library/cmd.html#module-cmd
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
80
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
81 .. _pyparsing: http://pyparsing.wikispaces.com/
52ab96d4f179 fix some Sphinx warnings
anatoly techtonik <techtonik@gmail.com>
parents: 336
diff changeset
82
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
83 Environment parameters
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
84 ======================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
85
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
86 Your application can define user-settable parameters
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
87 which your code can reference. Create them as class attributes
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
88 with their default values, and add them (with optional
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
89 documentation) to ``settable``.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
90
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
91 ::
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
92
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
93 from cmd2 import Cmd
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
94 class App(Cmd):
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
95 degrees_c = 22
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
96 sunny = False
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
97 settable = Cmd.settable + '''degrees_c temperature in Celsius
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
98 sunny'''
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
99 def do_sunbathe(self, arg):
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
100 if self.degrees_c < 20:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
101 result = "It's {temp} C - are you a penguin?".format(temp=self.degrees_c)
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
102 elif not self.sunny:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
103 result = 'Too dim.'
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
104 else:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
105 result = 'UV is bad for your skin.'
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
106 self.stdout.write(result + '\n')
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
107 app = App()
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
108 app.cmdloop()
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
109
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
110 ::
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
111
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
112 (Cmd) set --long
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
113 degrees_c: 22 # temperature in Celsius
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
114 sunny: False #
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
115 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
116 Too dim.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
117 (Cmd) set sunny yes
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
118 sunny - was: False
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
119 now: True
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
120 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
121 UV is bad for your skin.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
122 (Cmd) set degrees_c 13
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
123 degrees_c - was: 22
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
124 now: 13
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
125 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
126 It's 13 C - are you a penguin?
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
127
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
128
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
129 Commands with flags
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
130 ===================
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
131
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
132 All ``do_`` methods are responsible for interpreting
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
133 the arguments passed to them. However, ``cmd2`` lets
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
134 a ``do_`` methods accept Unix-style *flags*. It uses optparse_
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
135 to parse the flags, and they work the same way as for
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
136 that module.
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
137
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
138 Flags are defined with the ``options`` decorator,
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
139 which is passed a list of optparse_-style options,
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
140 each created with ``make_option``. The method
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
141 should accept a second argument, ``opts``, in
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
142 addition to ``args``; the flags will be stripped
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
143 from ``args``.
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
144
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
145 ::
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
146
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
147 @options([make_option('-p', '--piglatin', action="store_true", help="atinLay"),
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
148 make_option('-s', '--shout', action="store_true", help="N00B EMULATION MODE"),
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
149 make_option('-r', '--repeat', type="int", help="output [n] times")
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
150 ])
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
151 def do_speak(self, arg, opts=None):
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
152 """Repeats what you tell me to."""
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
153 arg = ''.join(arg)
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
154 if opts.piglatin:
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
155 arg = '%s%say' % (arg[1:].rstrip(), arg[0])
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
156 if opts.shout:
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
157 arg = arg.upper()
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
158 repetitions = opts.repeat or 1
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
159 for i in range(min(repetitions, self.maxrepeats)):
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
160 self.stdout.write(arg)
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
161 self.stdout.write('\n')
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
162
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
163 ::
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
164
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
165 (Cmd) say goodnight, gracie
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
166 goodnight, gracie
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
167 (Cmd) say -sp goodnight, gracie
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
168 OODNIGHT, GRACIEGAY
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
169 (Cmd) say -r 2 --shout goodnight, gracie
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
170 GOODNIGHT, GRACIE
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
171 GOODNIGHT, GRACIE
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
172
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
173 ``options`` takes an optional additional argument, ``arg_desc``.
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
174 If present, ``arg_desc`` will appear in place of ``arg`` in
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
175 the option's online help.
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
176
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
177 ::
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
178
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
179 @options([make_option('-t', '--train', action='store_true', help='by train')],
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
180 arg_desc='(from city) (to city)')
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
181 def do_travel(self, arg, opts=None):
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
182 'Gets you from (from city) to (to city).'
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
183
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
184
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
185 ::
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
186
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
187 (Cmd) help travel
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
188 Gets you from (from city) to (to city).
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
189 Usage: travel [options] (from-city) (to-city)
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
190
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
191 Options:
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
192 -h, --help show this help message and exit
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
193 -t, --train by train
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
194
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
195 .. _optparse:
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
196
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
197 .. _outputters:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
198
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
199 poutput, pfeedback, perror
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
200 ==========================
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
201
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
202 Standard ``cmd`` applications produce their output with ``self.stdout.write('output')`` (or with ``print``,
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
203 but ``print`` decreases output flexibility). ``cmd2`` applications can use
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
204 ``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')``
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
205 instead. These methods have these advantages:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
206
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
207 - More concise
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
208 - ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter.
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
209
336
8aa71e8f1064 alternatives
catherine@Drou
parents: 333
diff changeset
210 color
8aa71e8f1064 alternatives
catherine@Drou
parents: 333
diff changeset
211 =====
8aa71e8f1064 alternatives
catherine@Drou
parents: 333
diff changeset
212
411
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
213 Text output can be colored by wrapping it in the ``colorize`` method.
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
214
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
215 .. automethod:: cmd2.Cmd.colorize
336
8aa71e8f1064 alternatives
catherine@Drou
parents: 333
diff changeset
216
411
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
217 .. _quiet:
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
218
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
219 quiet
331
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
220 =====
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
221
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
222 Controls whether ``self.pfeedback('message')`` output is suppressed;
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
223 useful for non-essential feedback that the user may not always want
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
224 to read. ``quiet`` is only relevant if
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
225 ``app.pfeedback`` is sometimes used.
6306edc46a6e more docs
cat@eee
parents: 324
diff changeset
226
332
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
227 ``select``
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
228 ==========
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
229
411
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
230 Presents numbered options to user, as bash ``select``.
9d5ff2ddfdea doc update
Catherine Devlin <catherine.devlin@gmail.com>
parents: 388
diff changeset
231
332
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
232 ``app.select`` is called from within a method (not by the user directly; it is ``app.select``, not ``app.do_select``).
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
233
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
234 .. automethod:: cmd2.Cmd.select
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
235
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
236 ::
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
237
332
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
238 def do_eat(self, arg):
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
239 sauce = self.select('sweet salty', 'Sauce? ')
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
240 result = '{food} with {sauce} sauce, yum!'
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
241 result = result.format(food=arg, sauce=sauce)
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
242 self.stdout.write(result + '\n')
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
243
332
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
244 ::
49bea7cab179 doc refreshing refresh.bash
cat@eee
parents: 331
diff changeset
245
413
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
246 (Cmd) eat wheaties
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
247 1. sweet
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
248 2. salty
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
249 Sauce? 2
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
250 wheaties with salty sauce, yum!
f16f444a4d10 added arg_desc to @options, thanks Renzo Crispiatico
Catherine Devlin <catherine.devlin@gmail.com>
parents: 411
diff changeset
251