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