annotate docs/pycon2010/pycon2010.rst @ 373:a381f8dd3a45

mention py3
author cat@eee
date Fri, 19 Feb 2010 12:20:44 -0500
parents bf314710e64b
children 89e38f922c25
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
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
18 :height: 350px
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 ============
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
46
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
47 Also known as
344
catherine@Drou
parents: 337
diff changeset
48
catherine@Drou
parents: 337
diff changeset
49 - "Line-oriented command interpreter"
catherine@Drou
parents: 337
diff changeset
50 - "Command-line interface"
catherine@Drou
parents: 337
diff changeset
51 - "Shell"
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
52
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
53 1. Accepts free text input at prompt
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
54 2. Outputs lines of text
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
55 3. (repeat)
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
56
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
57 Examples
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
58 ========
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
59
344
catherine@Drou
parents: 337
diff changeset
60 * Bash, Korn, zsh
catherine@Drou
parents: 337
diff changeset
61 * Python shell
catherine@Drou
parents: 337
diff changeset
62 * screen
catherine@Drou
parents: 337
diff changeset
63 * Zork
catherine@Drou
parents: 337
diff changeset
64 * SQL clients: psql, SQL*\Plus, mysql...
catherine@Drou
parents: 337
diff changeset
65 * ed
catherine@Drou
parents: 337
diff changeset
66
catherine@Drou
parents: 337
diff changeset
67 .. ``ed`` proves that CLI is sometimes the wrong answer.
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
68
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
69 != Command Line Utilities
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
70 =========================
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
71
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
72 (``ls``, ``grep``, ``ping``, etc.)
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
73
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
74 1. Accepts arguments at invocation
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
75 2. executes
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
76 3. terminates
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
77
344
catherine@Drou
parents: 337
diff changeset
78 Use ``sys.argv``, ``optparse``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
79
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
80 !="Text User Interface", "Console"
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
81 ==================================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
82
344
catherine@Drou
parents: 337
diff changeset
83 * Use entire (session) screen
catherine@Drou
parents: 337
diff changeset
84 * I/O is *not* line-by-line
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
85 * See ``curses``, ``urwid``
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
86
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
87 .. image:: urwid.png
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
88 :height: 250px
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
89
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
90
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
91 Decide your priorities
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
92 ======================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
93
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
94 .. image:: strategy.png
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
95 :height: 350px
344
catherine@Drou
parents: 337
diff changeset
96
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
97 A ``cmd`` app: pirate.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
98 ========================
337
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
99
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
100 ::
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
101
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
102 from cmd import Cmd
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
103
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
104 class Pirate(Cmd):
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
105 pass
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
106
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
107 pirate = Pirate()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
108 pirate.cmdloop()
2ce34ad4e520 begin Pycon talk
catherine@Drou
parents:
diff changeset
109
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
110 .. Nothing here... but history and help
344
catherine@Drou
parents: 337
diff changeset
111
catherine@Drou
parents: 337
diff changeset
112 .. ctrl-r for bash-style history
catherine@Drou
parents: 337
diff changeset
113
catherine@Drou
parents: 337
diff changeset
114 Fundamental prrrinciple
catherine@Drou
parents: 337
diff changeset
115 =======================
catherine@Drou
parents: 337
diff changeset
116
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
117 .. class:: huge
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
118
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
119 Transform ``(Cmd) foo a b c``
344
catherine@Drou
parents: 337
diff changeset
120
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
121 to ``self.do_foo('a b c')``
344
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))
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
209
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
210 Other CLI packages
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
211 ==================
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
212
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
213 * cmdlin
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
214 * cmd2
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
215
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
216 Demo
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
217 ====
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
218
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
219 Convert ``cmd`` app to ``cmd2``
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
220
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
221 cmd2
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
222 ====
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
223
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
224 .. image:: schematic.png
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
225 :height: 350px
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
226
373
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
227 As you wish, Guido
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
228 ==================
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
229
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
230 Python 3 compatible
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
231
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
232 (um, mostly)
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
233
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
234 Absolutely free
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
235 ===============
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
236
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
237 * Script files
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
238 * Commands at invocation
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
239 * Output redirection
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
240 * Python
346
49dd1ce6cfd6 quitting after invocation commands
catherine@Drou
parents: 345
diff changeset
241 * Transcript-based testing
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
242
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
243 But wait, there's more
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
244 ======================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
245
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
246 * Abbreviated commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
247 * Shell commands
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
248 * Quitting
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
249 * Timing
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
250 * Echo
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
251 * Debug
345
6fe1e75e3a67 transcript test wasn't running pre and post cmd hooks
catherine@Drou
parents: 344
diff changeset
252
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
253 For a few keystrokes more...
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
254 ============================
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
255
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
256 * Default to shell
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
257 * Color output
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
258 * Shortcuts
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
259 * Multiline commands
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
260 * Environment variables
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
261
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
262 Minor changes: pirate7.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
263 =========================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
264
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
265 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
266
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
267 default_to_shell = True
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
268 multilineCommands = ['sing']
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
269 terminators = Cmd.terminators + ['...']
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
270 songcolor = 'blue'
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
271 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
272 Cmd.shortcuts.update({'~': 'sing'})
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
273 def do_sing(self, arg):
356
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
274 print(self.colorize(arg, self.songcolor))
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
275
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
276 Now how much would you pay?
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
277 ===========================
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
278
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
279 * options / flags
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
280 * Quiet (suppress feedback)
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
281 * BASH-style ``select``
d275d3beceff fix usage help name-stripping bug
catherine@dellzilla
parents: 353
diff changeset
282 * Parsing: terminators, suffixes
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
283
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
284 Options: pirate8.py
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
285 ===================
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
286
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
287 ::
347
432ccab7c6c8 going to try moving output redirection to outside precmd, postcmd hooks
catherine@Drou
parents: 346
diff changeset
288
351
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
289 def do_yo(self, arg, opts):
8a5bc9f5c28e cmd2 docs
catherine@Drou
parents: 347
diff changeset
290 chant = ['yo'] + ['ho'] * opts.ho
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
291 separator = ', ' if opts.commas else ' '
352
798c7f32a960 line spacing
catherine@Drou
parents: 351
diff changeset
292 chant = separator.join(chant)
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
293 print('{0} and a bottle of {1}'
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
294 .format(chant, arg))
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
295
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
296 Serious example: sqlpython
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
297 ==========================
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 ``cmd``-based app by Luca Canali @ CERN
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
300
364
29221236d1a1 updating refresh scripts
cat@eee
parents: 363
diff changeset
301 Replacement for Oracle SQL\*Plus
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
302
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
303 Now ``cmd2``-based; postgreSQL; MySQL
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
304
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
305 sqlpython features
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
306 ==================
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
307
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
308 * from ``cmd2``: scripts, redirection,
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
309 py, etc.
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
310 * multiple connections
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
311 * UNIX: ls, cat, grep
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
312 * Special output
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
313
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
314 File reporter
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
315 =============
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
316
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
317 Gather info: Python
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
318
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
319 Store: postgresql
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
320
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
321 Report: html
362
18e8487be095 try again to upload docs
cat@eee
parents: 357
diff changeset
322
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
323 Thank you
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
324 =========
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
325
373
a381f8dd3a45 mention py3
cat@eee
parents: 372
diff changeset
326 pypi.python.org/pypi/cmd2
372
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
327
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
328 catherinedevlin.blogspot.com
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
329
bf314710e64b can't make theme work
cat@eee
parents: 366
diff changeset
330 catherinedevlin.pythoneers.com
357
ce4448ca4088 leave office for pycon...
catherine@dellzilla
parents: 356
diff changeset
331
363
2b2836b783be added hook pic
cat@eee
parents: 362
diff changeset
332