Show More
@@ -44,26 +44,28 b' from IPython.utils.text import indent, wrap_paragraphs, dedent' | |||||
44 | # Descriptions for the various sections |
|
44 | # Descriptions for the various sections | |
45 | #----------------------------------------------------------------------------- |
|
45 | #----------------------------------------------------------------------------- | |
46 |
|
46 | |||
47 | flag_description = """ |
|
47 | # merge flags&aliases into options | |
48 | Flags are command-line arguments passed as '--<flag>'. |
|
48 | option_description = """ | |
49 | These take no parameters, unlike regular key-value arguments. |
|
49 | IPython command-line arguments are passed as '--<flag>', or '--<name>=<value>'. | |
50 | They are typically used for setting boolean flags, or enabling |
|
|||
51 | modes that involve setting multiple options together. |
|
|||
52 | """.strip() # trim newlines of front and back |
|
|||
53 |
|
50 | |||
54 | alias_description = """ |
|
51 | Arguments that take values are actually aliases to full Configurables, whose | |
55 | These are commonly set parameters, given abbreviated aliases for convenience. |
|
52 | aliases are listed on the help line. For more information on full | |
56 | They are set in the same `--name=value` way as class parameters, where |
|
53 | configurables, see '--help-all'. | |
57 | <name> is replaced by the real parameter for which it is an alias. |
|
|||
58 | """.strip() # trim newlines of front and back |
|
54 | """.strip() # trim newlines of front and back | |
59 |
|
55 | |||
60 | keyvalue_description = """ |
|
56 | keyvalue_description = """ | |
61 | Parameters are set from command-line arguments of the form: |
|
57 | Parameters are set from command-line arguments of the form: | |
62 | `--Class.trait=value`. |
|
58 | `--Class.trait=value`. | |
63 | This line is evaluated in Python, so simple expressions are allowed, e.g. |
|
59 | This line is evaluated in Python, so simple expressions are allowed, e.g.:: | |
64 |
|
|
60 | `--C.a='range(3)'` For setting C.a=[0,1,2]. | |
65 | """.strip() # trim newlines of front and back |
|
61 | """.strip() # trim newlines of front and back | |
66 |
|
62 | |||
|
63 | subcommand_description = """ | |||
|
64 | Subcommands are launched as `{app} cmd [args]`. For information on using | |||
|
65 | subcommand 'cmd', do: `{app} cmd -h`. | |||
|
66 | """.strip().format(app=os.path.basename(sys.argv[0])) | |||
|
67 | # get running program name | |||
|
68 | ||||
67 | #----------------------------------------------------------------------------- |
|
69 | #----------------------------------------------------------------------------- | |
68 | # Application class |
|
70 | # Application class | |
69 | #----------------------------------------------------------------------------- |
|
71 | #----------------------------------------------------------------------------- | |
@@ -84,9 +86,9 b' class Application(SingletonConfigurable):' | |||||
84 | # of the help. |
|
86 | # of the help. | |
85 | description = Unicode(u'This is an application.') |
|
87 | description = Unicode(u'This is an application.') | |
86 | # default section descriptions |
|
88 | # default section descriptions | |
87 |
|
|
89 | option_description = Unicode(option_description) | |
88 | alias_description = Unicode(alias_description) |
|
|||
89 | keyvalue_description = Unicode(keyvalue_description) |
|
90 | keyvalue_description = Unicode(keyvalue_description) | |
|
91 | subcommand_description = Unicode(subcommand_description) | |||
90 |
|
92 | |||
91 |
|
93 | |||
92 | # A sequence of Configurable subclasses whose config=True attributes will |
|
94 | # A sequence of Configurable subclasses whose config=True attributes will | |
@@ -190,13 +192,7 b' class Application(SingletonConfigurable):' | |||||
190 | if not self.aliases: |
|
192 | if not self.aliases: | |
191 | return |
|
193 | return | |
192 |
|
194 | |||
193 |
lines = [ |
|
195 | lines = [] | |
194 | lines.append('-'*len(lines[0])) |
|
|||
195 | lines.append('') |
|
|||
196 | for p in wrap_paragraphs(self.alias_description): |
|
|||
197 | lines.append(p) |
|
|||
198 | lines.append('') |
|
|||
199 |
|
||||
200 | classdict = {} |
|
196 | classdict = {} | |
201 | for cls in self.classes: |
|
197 | for cls in self.classes: | |
202 | # include all parents (up to, but excluding Configurable) in available names |
|
198 | # include all parents (up to, but excluding Configurable) in available names | |
@@ -212,7 +208,7 b' class Application(SingletonConfigurable):' | |||||
212 | # reformat first line |
|
208 | # reformat first line | |
213 | help[0] = help[0].replace(longname, alias) + ' (%s)'%longname |
|
209 | help[0] = help[0].replace(longname, alias) + ' (%s)'%longname | |
214 | lines.extend(help) |
|
210 | lines.extend(help) | |
215 | lines.append('') |
|
211 | # lines.append('') | |
216 | print os.linesep.join(lines) |
|
212 | print os.linesep.join(lines) | |
217 |
|
213 | |||
218 | def print_flag_help(self): |
|
214 | def print_flag_help(self): | |
@@ -220,18 +216,26 b' class Application(SingletonConfigurable):' | |||||
220 | if not self.flags: |
|
216 | if not self.flags: | |
221 | return |
|
217 | return | |
222 |
|
218 | |||
223 |
lines = [ |
|
219 | lines = [] | |
224 | lines.append('-'*len(lines[0])) |
|
|||
225 | lines.append('') |
|
|||
226 | for p in wrap_paragraphs(self.flag_description): |
|
|||
227 | lines.append(p) |
|
|||
228 | lines.append('') |
|
|||
229 |
|
||||
230 | for m, (cfg,help) in self.flags.iteritems(): |
|
220 | for m, (cfg,help) in self.flags.iteritems(): | |
231 | lines.append('--'+m) |
|
221 | lines.append('--'+m) | |
232 | lines.append(indent(dedent(help.strip()))) |
|
222 | lines.append(indent(dedent(help.strip()))) | |
|
223 | # lines.append('') | |||
|
224 | print os.linesep.join(lines) | |||
|
225 | ||||
|
226 | def print_options(self): | |||
|
227 | if not self.flags and not self.aliases: | |||
|
228 | return | |||
|
229 | lines = ['Options'] | |||
|
230 | lines.append('-'*len(lines[0])) | |||
233 | lines.append('') |
|
231 | lines.append('') | |
234 | print '\n'.join(lines) |
|
232 | for p in wrap_paragraphs(self.option_description): | |
|
233 | lines.append(p) | |||
|
234 | lines.append('') | |||
|
235 | print os.linesep.join(lines) | |||
|
236 | self.print_flag_help() | |||
|
237 | self.print_alias_help() | |||
|
238 | ||||
235 |
|
239 | |||
236 | def print_subcommands(self): |
|
240 | def print_subcommands(self): | |
237 | """Print the subcommand part of the help.""" |
|
241 | """Print the subcommand part of the help.""" | |
@@ -240,12 +244,16 b' class Application(SingletonConfigurable):' | |||||
240 |
|
244 | |||
241 | lines = ["Subcommands"] |
|
245 | lines = ["Subcommands"] | |
242 | lines.append('-'*len(lines[0])) |
|
246 | lines.append('-'*len(lines[0])) | |
|
247 | lines.append('') | |||
|
248 | for p in wrap_paragraphs(self.subcommand_description): | |||
|
249 | lines.append(p) | |||
|
250 | lines.append('') | |||
243 | for subc, (cls,help) in self.subcommands.iteritems(): |
|
251 | for subc, (cls,help) in self.subcommands.iteritems(): | |
244 | lines.append("%s : %s"%(subc, cls)) |
|
252 | lines.append("%s : %s"%(subc, cls)) | |
245 | if help: |
|
253 | if help: | |
246 | lines.append(indent(dedent(help.strip()))) |
|
254 | lines.append(indent(dedent(help.strip()))) | |
247 | lines.append('') |
|
255 | lines.append('') | |
248 |
print |
|
256 | print os.linesep.join(lines) | |
249 |
|
257 | |||
250 | def print_help(self, classes=False): |
|
258 | def print_help(self, classes=False): | |
251 | """Print the help for each Configurable class in self.classes. |
|
259 | """Print the help for each Configurable class in self.classes. | |
@@ -253,8 +261,7 b' class Application(SingletonConfigurable):' | |||||
253 | If classes=False (the default), only flags and aliases are printed. |
|
261 | If classes=False (the default), only flags and aliases are printed. | |
254 | """ |
|
262 | """ | |
255 | self.print_subcommands() |
|
263 | self.print_subcommands() | |
256 |
self.print_ |
|
264 | self.print_options() | |
257 | self.print_alias_help() |
|
|||
258 |
|
265 | |||
259 | if classes: |
|
266 | if classes: | |
260 | if self.classes: |
|
267 | if self.classes: |
General Comments 0
You need to be logged in to leave comments.
Login now