annotate docs/unfreefeatures.rst @ 328:7b2bca3951a7

locals_in_py
author cat@eee
date Fri, 12 Feb 2010 15:35:48 -0500
parents 21584174d865
children 6306edc46a6e
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
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
5 Command shortcuts
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
6 =================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
7
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
8 .. _parameters:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
9
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
10 Environment parameters
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
11 ======================
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
12
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
13 Your application can define user-settable parameters
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
14 which your code can reference. Create them as class attributes
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
15 with their default values, and add them (with optional
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
16 documentation) to ``settable``.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
17
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
18 ::
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
19
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
20 from cmd2 import Cmd
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
21 class App(Cmd):
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
22 degrees_c = 22
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
23 sunny = False
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
24 settable = Cmd.settable + '''degrees_c temperature in Celsius
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
25 sunny'''
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
26 def do_sunbathe(self, arg):
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
27 if self.degrees_c < 20:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
28 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
29 elif not self.sunny:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
30 result = 'Too dim.'
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
31 else:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
32 result = 'UV is bad for your skin.'
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
33 self.stdout.write(result + '\n')
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
34 app = App()
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
35 app.cmdloop()
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
36
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
37 ::
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
38
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
39 (Cmd) set --long
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
40 degrees_c: 22 # temperature in Celsius
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
41 sunny: False #
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
42 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
43 Too dim.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
44 (Cmd) set sunny yes
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
45 sunny - was: False
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
46 now: True
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
47 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
48 UV is bad for your skin.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
49 (Cmd) set degrees_c 13
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
50 degrees_c - was: 22
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
51 now: 13
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
52 (Cmd) sunbathe
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
53 It's 13 C - are you a penguin?
316
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
54
8a76f597d2f9 oops, remove benchmark references
cat@eee
parents: 315
diff changeset
55
315
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
56 Commands with flags
a08c50b7d3d3 doc skeleton
cat@eee
parents:
diff changeset
57 ===================
324
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
58
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
59 .. _outputters:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
60
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
61 poutput, pfeedback, perror
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
62 ==========================
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
63
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
64 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
65 but ``print`` decreases output flexibility). ``cmd2`` applications can use
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
66 ``self.poutput('output')``, ``self.pfeedback('message')``, and ``self.perror('errmsg')``
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
67 instead. These methods have these advantages:
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
68
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
69 - More concise
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
70 - ``.pfeedback()`` destination is controlled by :ref:`quiet` parameter.
21584174d865 make SHOW TABLES work
catherine@dellzilla
parents: 316
diff changeset
71