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