##// END OF EJS Templates
Command line examples added for non-parallel apps.
Brian Granger -
Show More
@@ -89,7 +89,9 b' class Application(SingletonConfigurable):'
89 option_description = Unicode(option_description)
89 option_description = Unicode(option_description)
90 keyvalue_description = Unicode(keyvalue_description)
90 keyvalue_description = Unicode(keyvalue_description)
91 subcommand_description = Unicode(subcommand_description)
91 subcommand_description = Unicode(subcommand_description)
92
92
93 # The usage and example string that goes at the end of the help string.
94 examples = Unicode()
93
95
94 # A sequence of Configurable subclasses whose config=True attributes will
96 # A sequence of Configurable subclasses whose config=True attributes will
95 # be exposed at the command line.
97 # be exposed at the command line.
@@ -170,7 +172,7 b' class Application(SingletonConfigurable):'
170 self._log_formatter = logging.Formatter("[%(name)s] %(message)s")
172 self._log_formatter = logging.Formatter("[%(name)s] %(message)s")
171 self._log_handler.setFormatter(self._log_formatter)
173 self._log_handler.setFormatter(self._log_formatter)
172 self.log.addHandler(self._log_handler)
174 self.log.addHandler(self._log_handler)
173
175
174 def initialize(self, argv=None):
176 def initialize(self, argv=None):
175 """Do the basic steps to configure me.
177 """Do the basic steps to configure me.
176
178
@@ -285,6 +287,19 b' class Application(SingletonConfigurable):'
285 print p
287 print p
286 print
288 print
287
289
290 def print_examples(self):
291 """Print usage and examples.
292
293 This usage string goes at the end of the command line help string
294 and should contain examples of the application's usage.
295 """
296 if self.examples:
297 print "Examples"
298 print "--------"
299 print
300 print indent(dedent(self.examples.strip()))
301 print
302
288 def print_version(self):
303 def print_version(self):
289 """Print the version string."""
304 """Print the version string."""
290 print self.version
305 print self.version
@@ -327,6 +342,7 b' class Application(SingletonConfigurable):'
327 if '-h' in argv or '--help' in argv or '--help-all' in argv:
342 if '-h' in argv or '--help' in argv or '--help-all' in argv:
328 self.print_description()
343 self.print_description()
329 self.print_help('--help-all' in argv)
344 self.print_help('--help-all' in argv)
345 self.print_examples()
330 self.exit(0)
346 self.exit(0)
331
347
332 if '--version' in argv:
348 if '--version' in argv:
@@ -341,6 +357,7 b' class Application(SingletonConfigurable):'
341 except (TraitError, ArgumentError) as e:
357 except (TraitError, ArgumentError) as e:
342 self.print_description()
358 self.print_description()
343 self.print_help()
359 self.print_help()
360 self.print_examples()
344 self.log.fatal(str(e))
361 self.log.fatal(str(e))
345 self.exit(1)
362 self.exit(1)
346 # store unparsed args in extra_args
363 # store unparsed args in extra_args
@@ -79,7 +79,6 b' where you can edit ipython_config.py to start configuring IPython.'
79 #-----------------------------------------------------------------------------
79 #-----------------------------------------------------------------------------
80
80
81
81
82
83 class ProfileList(Application):
82 class ProfileList(Application):
84 name = u'ipython-profile'
83 name = u'ipython-profile'
85 description = list_help
84 description = list_help
@@ -128,9 +127,15 b" create_flags.update(boolean_flag('parallel', 'ProfileCreate.parallel',"
128 "Include parallel computing config files",
127 "Include parallel computing config files",
129 "Don't include parallel computing config files"))
128 "Don't include parallel computing config files"))
130
129
130 create_examples = """
131 ipython profile create foo # create profile foo
132 ipython profile create foo --init # create with default config files
133 """
134
131 class ProfileCreate(BaseIPythonApplication):
135 class ProfileCreate(BaseIPythonApplication):
132 name = u'ipython-profile'
136 name = u'ipython-profile'
133 description = create_help
137 description = create_help
138 examples = create_examples
134 auto_create = Bool(True, config=False)
139 auto_create = Bool(True, config=False)
135
140
136 def _copy_config_files_default(self):
141 def _copy_config_files_default(self):
@@ -199,10 +204,16 b' class ProfileCreate(BaseIPythonApplication):'
199 def stage_default_config_file(self):
204 def stage_default_config_file(self):
200 pass
205 pass
201
206
207 main_examples = """
208 ipython profile create -h # show the help string for the create subcommand
209 ipython profile list -h # show the help string for the list subcommand
210 """
211
202 class ProfileApp(Application):
212 class ProfileApp(Application):
203 name = u'ipython-profile'
213 name = u'ipython-profile'
204 description = profile_help
214 description = profile_help
205
215 examples = main_examples
216
206 subcommands = Dict(dict(
217 subcommands = Dict(dict(
207 create = (ProfileCreate, "Create a new profile dir with default config files"),
218 create = (ProfileCreate, "Create a new profile dir with default config files"),
208 list = (ProfileList, "List existing profiles")
219 list = (ProfileList, "List existing profiles")
@@ -218,6 +218,12 b' aliases.update(dict('
218 #-----------------------------------------------------------------------------
218 #-----------------------------------------------------------------------------
219 # IPythonQtConsole
219 # IPythonQtConsole
220 #-----------------------------------------------------------------------------
220 #-----------------------------------------------------------------------------
221
222 qt_examples = """
223 ipython qtconsole # start the qtconsole
224 ipython qtconsole --pylab=inline # start with pylab in inline plotting mode
225 """
226
221 class IPythonQtConsoleApp(BaseIPythonApplication):
227 class IPythonQtConsoleApp(BaseIPythonApplication):
222 name = 'ipython-qtconsole'
228 name = 'ipython-qtconsole'
223 default_config_file_name='ipython_config.py'
229 default_config_file_name='ipython_config.py'
@@ -231,7 +237,8 b' class IPythonQtConsoleApp(BaseIPythonApplication):'
231 The QtConsole supports various extra features beyond the
237 The QtConsole supports various extra features beyond the
232
238
233 """
239 """
234
240 examples = qt_examples
241
235 classes = [IPKernelApp, IPythonWidget, ZMQInteractiveShell, ProfileDir, Session]
242 classes = [IPKernelApp, IPythonWidget, ZMQInteractiveShell, ProfileDir, Session]
236 flags = Dict(flags)
243 flags = Dict(flags)
237 aliases = Dict(aliases)
244 aliases = Dict(aliases)
@@ -168,12 +168,23 b' aliases.update(dict('
168 # Main classes and functions
168 # Main classes and functions
169 #-----------------------------------------------------------------------------
169 #-----------------------------------------------------------------------------
170
170
171 examples = """
172 ipython --pylab # start in pylab mode
173 ipython --pylab=qt # start in pylab mode with the qt4 backend
174 ipython --log_level=DEBUG # set logging to DEBUG
175 ipython --profile=foo # start with profile foo
176 ipython qtconsole # start the qtconsole GUI application
177 ipython profile -h # show the help string for the profile subcmd
178 ipython qtconsole -h # show the help string for the qtconsole subcmd
179 """
180
171 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
181 class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp):
172 name = u'ipython'
182 name = u'ipython'
173 description = usage.cl_usage
183 description = usage.cl_usage
174 default_config_file_name = default_config_file_name
184 default_config_file_name = default_config_file_name
175 crash_handler_class = IPAppCrashHandler
185 crash_handler_class = IPAppCrashHandler
176
186 examples = examples
187
177 flags = Dict(flags)
188 flags = Dict(flags)
178 aliases = Dict(aliases)
189 aliases = Dict(aliases)
179 classes = [InteractiveShellApp, TerminalInteractiveShell, ProfileDir, PlainTextFormatter]
190 classes = [InteractiveShellApp, TerminalInteractiveShell, ProfileDir, PlainTextFormatter]
General Comments 0
You need to be logged in to leave comments. Login now