annotate docs/pycon2010/pycon2010.rst @ 366:40cba30b6125

refresh corrections
author cat@eee
date Thu, 18 Feb 2010 14:20:43 -0500
parents 29221236d1a1
children bf314710e64b
rev   line source
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
1 ================================================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
2 Easy command-line interpreters with cmd and cmd2
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
3 ================================================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
4
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
5 :author: Catherine Devlin
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
6 :date: 2010-02-20
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
7
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
8 Quit scribbling
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
9 ===============
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
10
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
11 Slides are *already* posted at
366
40cba30b6125 refresh corrections
cat@eee
parents: 364
diff changeset
12 homepage: http://pypi.python.org/pypi/cmd2
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
13
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
14 Web 2.0
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
15 =======
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
16
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
17 .. image:: web-2-0-logos.gif
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
18 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
19
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
20 But first...
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
21 ============
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
22
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
23 .. image:: sargon.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
24 :height: 250px
344
catherine@Drou
parents: 337
diff changeset
25
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
26 .. image:: akkad.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
27 :height: 250px
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
28
344
catherine@Drou
parents: 337
diff changeset
29 Sargon the Great
catherine@Drou
parents: 337
diff changeset
30 Founder of Akkadian Empire
catherine@Drou
parents: 337
diff changeset
31
catherine@Drou
parents: 337
diff changeset
32 .. twenty-third century BC
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
33
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
34 In between
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
35 ==========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
36
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
37 .. image:: apple.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
38 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
39
344
catherine@Drou
parents: 337
diff changeset
40 Command-Line Interface
catherine@Drou
parents: 337
diff changeset
41 Unlike the Akkadian Empire,
catherine@Drou
parents: 337
diff changeset
42 the CLI will never die.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
43
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
44 Defining CLI
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
45 ============
344
catherine@Drou
parents: 337
diff changeset
46
catherine@Drou
parents: 337
diff changeset
47 - "Line-oriented command interpreter"
catherine@Drou
parents: 337
diff changeset
48 - "Command-line interface"
catherine@Drou
parents: 337
diff changeset
49 - "Shell"
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
50
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
51 1. Accepts free text input at prompt
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
52 2. Outputs lines of text
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
53 3. (repeat)
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
54
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
55 Examples
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
56 ========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
57
344
catherine@Drou
parents: 337
diff changeset
58 * Bash, Korn, zsh
catherine@Drou
parents: 337
diff changeset
59 * Python shell
catherine@Drou
parents: 337
diff changeset
60 * screen
catherine@Drou
parents: 337
diff changeset
61 * Zork
catherine@Drou
parents: 337
diff changeset
62 * SQL clients: psql, SQL*\Plus, mysql...
catherine@Drou
parents: 337
diff changeset
63 * ed
catherine@Drou
parents: 337
diff changeset
64
catherine@Drou
parents: 337
diff changeset
65 .. ``ed`` proves that CLI is sometimes the wrong answer.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
66
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
67 != Command Line Utilities
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
68 =========================
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
69
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
70 (``ls``, ``grep``, ``ping``, etc.)
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
71
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
72 1. Accepts arguments at invocation
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
73 2. executes
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
74 3. terminates
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
75
344
catherine@Drou
parents: 337
diff changeset
76 Use ``sys.argv``, ``optparse``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
77
344
catherine@Drou
parents: 337
diff changeset
78 != "Text User Interfaces", "Consoles"
catherine@Drou
parents: 337
diff changeset
79 =====================================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
80
344
catherine@Drou
parents: 337
diff changeset
81 * Use entire (session) screen
catherine@Drou
parents: 337
diff changeset
82 * I/O is *not* line-by-line
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
83
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
84 .. image:: urwid.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
85 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
86
344
catherine@Drou
parents: 337
diff changeset
87 Use ``curses``, ``urwid``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
88
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
89 Priorities
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
90 ==========
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
91
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
92 .. image:: strategy.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
93 :height: 250px
344
catherine@Drou
parents: 337
diff changeset
94
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
95 A ``cmd`` app: pirate.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
96 ========================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
97
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
98 ::
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
99
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
100 from cmd import Cmd
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
101
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
102 class Pirate(Cmd):
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
103 pass
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
104
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
105 pirate = Pirate()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
106 pirate.cmdloop()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
107
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
108 .. Nothing here... but history and help
344
catherine@Drou
parents: 337
diff changeset
109
catherine@Drou
parents: 337
diff changeset
110 .. ctrl-r for bash-style history
catherine@Drou
parents: 337
diff changeset
111
catherine@Drou
parents: 337
diff changeset
112 Fundamental prrrinciple
catherine@Drou
parents: 337
diff changeset
113 =======================
catherine@Drou
parents: 337
diff changeset
114
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
115 .. class:: huge
344
catherine@Drou
parents: 337
diff changeset
116
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
117 ::
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
118
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
119 (Cmd) foo a b c
344
catherine@Drou
parents: 337
diff changeset
120
catherine@Drou
parents: 337
diff changeset
121 ``self.do_foo('a b c')``
catherine@Drou
parents: 337
diff changeset
122
catherine@Drou
parents: 337
diff changeset
123 ``do_``-methods: pirate2.py
catherine@Drou
parents: 337
diff changeset
124 ===========================
catherine@Drou
parents: 337
diff changeset
125
catherine@Drou
parents: 337
diff changeset
126 ::
catherine@Drou
parents: 337
diff changeset
127
catherine@Drou
parents: 337
diff changeset
128 class Pirate(Cmd):
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
129 gold = 3
344
catherine@Drou
parents: 337
diff changeset
130 def do_loot(self, arg):
catherine@Drou
parents: 337
diff changeset
131 'Seize booty frrrom a passing ship.'
catherine@Drou
parents: 337
diff changeset
132 self.gold += 1
catherine@Drou
parents: 337
diff changeset
133 print('Now we gots {0} doubloons'.format(self.gold))
catherine@Drou
parents: 337
diff changeset
134 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
135 'Drown your sorrrows in rrrum.'
catherine@Drou
parents: 337
diff changeset
136 self.gold -= 1
catherine@Drou
parents: 337
diff changeset
137 print('Now we gots {0} doubloons'.format(self.gold))
catherine@Drou
parents: 337
diff changeset
138
catherine@Drou
parents: 337
diff changeset
139 .. do_methods; more help
catherine@Drou
parents: 337
diff changeset
140
catherine@Drou
parents: 337
diff changeset
141 Hooks
catherine@Drou
parents: 337
diff changeset
142 =====
catherine@Drou
parents: 337
diff changeset
143
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
144 .. image:: hook.jpg
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
145 :height: 250px
344
catherine@Drou
parents: 337
diff changeset
146
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
147 preloop, postloop, precmd, postcmd
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
148
344
catherine@Drou
parents: 337
diff changeset
149 Hooks: pirate3.py
catherine@Drou
parents: 337
diff changeset
150 =================
catherine@Drou
parents: 337
diff changeset
151
catherine@Drou
parents: 337
diff changeset
152 ::
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
153
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
154 def do_loot(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
155 'Seize booty from a passing ship.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
156 self.gold += 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
157 def do_drink(self, arg):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
158 'Drown your sorrrows in rrrum.'
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
159 self.gold -= 1
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
160 def precmd(self, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
161 self.initial_gold = self.gold
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
162 return line
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
163 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
164 if self.gold != self.initial_gold:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
165 print('Now we gots {0} doubloons'.format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
166
catherine@Drou
parents: 337
diff changeset
167 Arguments: pirate4.py
catherine@Drou
parents: 337
diff changeset
168 =====================
catherine@Drou
parents: 337
diff changeset
169
catherine@Drou
parents: 337
diff changeset
170 ::
catherine@Drou
parents: 337
diff changeset
171
catherine@Drou
parents: 337
diff changeset
172 def do_drink(self, arg):
catherine@Drou
parents: 337
diff changeset
173 '''Drown your sorrrows in rrrum.
catherine@Drou
parents: 337
diff changeset
174
catherine@Drou
parents: 337
diff changeset
175 drink [n] - drink [n] barrel[s] o' rum.'''
catherine@Drou
parents: 337
diff changeset
176 try:
catherine@Drou
parents: 337
diff changeset
177 self.gold -= int(arg)
catherine@Drou
parents: 337
diff changeset
178 except:
catherine@Drou
parents: 337
diff changeset
179 if arg:
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
180 print('''What's "{0}"? I'll take rrrum.'''
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
181 .format(arg))
344
catherine@Drou
parents: 337
diff changeset
182 self.gold -= 1
catherine@Drou
parents: 337
diff changeset
183
catherine@Drou
parents: 337
diff changeset
184 quitting: pirate5.py
catherine@Drou
parents: 337
diff changeset
185 ====================
catherine@Drou
parents: 337
diff changeset
186
catherine@Drou
parents: 337
diff changeset
187 ::
catherine@Drou
parents: 337
diff changeset
188
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
189 def postcmd(self, stop, line):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
190 if self.gold != self.initial_gold:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
191 print('Now we gots {0} doubloons'.format(self.gold))
344
catherine@Drou
parents: 337
diff changeset
192 if self.gold < 0:
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
193 print("Off to debtorrr's prison. Game overrr.")
344
catherine@Drou
parents: 337
diff changeset
194 return True
catherine@Drou
parents: 337
diff changeset
195 return stop
catherine@Drou
parents: 337
diff changeset
196 def do_quit(self, arg):
catherine@Drou
parents: 337
diff changeset
197 print("Quiterrr!")
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
198 return True
344
catherine@Drou
parents: 337
diff changeset
199
catherine@Drou
parents: 337
diff changeset
200 prompts and defaults: pirate6.py
catherine@Drou
parents: 337
diff changeset
201 ================================
catherine@Drou
parents: 337
diff changeset
202
catherine@Drou
parents: 337
diff changeset
203 ::
catherine@Drou
parents: 337
diff changeset
204
catherine@Drou
parents: 337
diff changeset
205 prompt = 'arrr> '
catherine@Drou
parents: 337
diff changeset
206 def default(self, line):
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
207 print('What mean ye by "{0}"?'
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
208 .format(line))
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
209
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
210 cmd2
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
211 ====
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
212
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
213 .. image:: schematic.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
214 :height: 250px
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
215
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
216 Absolutely free
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
217 ===============
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
218
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
219 * Script files
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
220 * Commands at invocation
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
221 * Output redirection
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
222 * Python
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
223 * Transcript-based testing
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
224
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
225 But wait, there's more
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
226 ======================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
227
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
228 * Abbreviated commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
229 * Shell commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
230 * Quitting
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
231 * Timing
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
232 * Echo
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
233 * Debug
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
234
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
235 For a few keystrokes more...
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
236 ============================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
237
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
238 * Default to shell
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
239 * Color output
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
240 * Shortcuts
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
241 * Multiline commands
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
242 * Environment variables
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
243
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
244 Minor changes: pirate7.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
245 =========================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
246
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
247 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
248
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
249 default_to_shell = True
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
250 multilineCommands = ['sing']
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
251 terminators = Cmd.terminators + ['...']
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
252 songcolor = 'blue'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
253 settable = Cmd.settable + 'songcolor Color to ``sing`` in (red/blue/green/cyan/magenta, bold, underline)'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
254 Cmd.shortcuts.update({'~': 'sing'})
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
255 def do_sing(self, arg):
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
256 print(self.colorize(arg, self.songcolor))
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
257
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
258 Now how much would you pay?
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
259 ===========================
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
260
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
261 * options / flags
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
262 * Quiet (suppress feedback)
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
263 * BASH-style ``select``
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
264 * Parsing: terminators, suffixes
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
265
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
266 Options: pirate8.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
267 ===================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
268
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
269 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
270
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
271 @options([make_option('--ho', type='int', help="How often to chant 'ho'", default=2),
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
272 make_option('-c', '--commas', action="store_true", help="Interspers commas")])
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
273 def do_yo(self, arg, opts):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
274 chant = ['yo'] + ['ho'] * opts.ho
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
275 if opts.commas:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
276 separator = ', '
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
277 else:
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
278 separator = ' '
352
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
279 chant = separator.join(chant)
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
280 print('{0} and a bottle of {1}'.format(chant, arg))
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
281
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
282 Serious example: sqlpython
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
283 ==========================
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
284
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
285 ``cmd``-based app by Luca Canali @ CERN
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
286
364
29221236d1a1 updating refresh scripts
cat@eee
parents: 363
diff changeset
287 Replacement for Oracle SQL\*Plus
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
288
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
289 Now ``cmd2``-based; postgreSQL; MySQL
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
290
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
291 sqlpython features
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
292 ==================
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
293
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
294 Everything in ``cmd2``
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
295 (scripts, redirection, py)
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
296
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
297 Multi connections
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
298
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
299 ls, grep
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
300
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
301 Output to html, csv, inserts, bar graphs
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
302
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
303 py session with bind variables
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
304
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
305
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
306
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
307