##// END OF EJS Templates
print usage on invalid command-line arguments
MinRK -
Show More
@@ -24,7 +24,7 b' import sys'
24 24
25 25 from IPython.config.configurable import SingletonConfigurable
26 26 from IPython.config.loader import (
27 KeyValueConfigLoader, PyFileConfigLoader, Config
27 KeyValueConfigLoader, PyFileConfigLoader, Config, ArgumentError
28 28 )
29 29
30 30 from IPython.utils.traitlets import (
@@ -175,8 +175,10 b' class Application(SingletonConfigurable):'
175 175 lines.append('')
176 176
177 177 classdict = {}
178 for c in self.classes:
179 classdict[c.__name__] = c
178 for cls in self.classes:
179 # include all parents in available names
180 for c in cls.mro():
181 classdict[c.__name__] = c
180 182
181 183 for alias, longname in self.aliases.iteritems():
182 184 classname, traitname = longname.split('.',1)
@@ -212,7 +214,7 b' class Application(SingletonConfigurable):'
212 214
213 215 lines = ["Subcommands"]
214 216 lines.append('-'*len(lines[0]))
215 for subc, cls,help in self.subcommands:
217 for subc, (cls,help) in self.subcommands.iteritems():
216 218 lines.append("%s : %s"%(subc, cls))
217 219 if help:
218 220 lines.append(indent(help, flatten=True))
@@ -267,14 +269,14 b' class Application(SingletonConfigurable):'
267 269 self.print_description()
268 270 self.print_subcommands()
269 271 self.exit(0)
270 subapp = self.subcommands.get(subc, None)
272 subapp,help = self.subcommands.get(subc, (None,None))
271 273 if subapp is None:
272 274 self.print_description()
273 275 print "No such subcommand: %r"%subc
274 276 print
275 277 self.print_subcommands()
276 278 self.exit(1)
277
279
278 280 if isinstance(subapp, basestring):
279 281 subapp = import_item(subapp)
280 282
@@ -308,7 +310,13 b' class Application(SingletonConfigurable):'
308 310
309 311 loader = KeyValueConfigLoader(argv=argv, aliases=self.aliases,
310 312 flags=self.flags)
311 config = loader.load_config()
313 try:
314 config = loader.load_config()
315 except ArgumentError as e:
316 self.log.fatal(str(e))
317 self.print_description()
318 self.print_help()
319 self.exit(1)
312 320 self.update_config(config)
313 321
314 322 def load_config_file(self, filename, path=None):
@@ -36,6 +36,9 b' class ConfigError(Exception):'
36 36 class ConfigLoaderError(ConfigError):
37 37 pass
38 38
39 class ArgumentError(ConfigLoaderError):
40 pass
41
39 42 #-----------------------------------------------------------------------------
40 43 # Argparse fix
41 44 #-----------------------------------------------------------------------------
@@ -403,14 +406,14 b' class KeyValueConfigLoader(CommandLineConfigLoader):'
403 406 m = item[2:]
404 407 cfg,_ = flags.get(m, (None,None))
405 408 if cfg is None:
406 raise ValueError("Unrecognized flag: %r"%item)
409 raise ArgumentError("Unrecognized flag: %r"%item)
407 410 elif isinstance(cfg, (dict, Config)):
408 411 # update self.config with Config:
409 412 self.config.update(cfg)
410 413 else:
411 414 raise ValueError("Invalid flag: %r"%flag)
412 415 else:
413 raise ValueError("Invalid argument: %r"%item)
416 raise ArgumentError("Invalid argument: %r"%item)
414 417 return self.config
415 418
416 419 class ArgParseConfigLoader(CommandLineConfigLoader):
General Comments 0
You need to be logged in to leave comments. Login now