##// END OF EJS Templates
make subcommands optional
MinRK -
Show More
@@ -20,6 +20,7 b' Authors:'
20 20
21 21 from copy import deepcopy
22 22 import logging
23 import re
23 24 import sys
24 25
25 26 from IPython.config.configurable import SingletonConfigurable
@@ -176,8 +177,8 b' class Application(SingletonConfigurable):'
176 177
177 178 classdict = {}
178 179 for cls in self.classes:
179 # include all parents in available names
180 for c in cls.mro():
180 # include all parents (up to, but excluding Configurable) in available names
181 for c in cls.mro()[:-3]:
181 182 classdict[c.__name__] = c
182 183
183 184 for alias, longname in self.aliases.iteritems():
@@ -226,6 +227,7 b' class Application(SingletonConfigurable):'
226 227
227 228 If classes=False (the default), only flags and aliases are printed
228 229 """
230 self.print_subcommands()
229 231 self.print_flag_help()
230 232 self.print_alias_help()
231 233
@@ -264,11 +266,6 b' class Application(SingletonConfigurable):'
264 266
265 267 def initialize_subcommand(self, subc, argv=None):
266 268 """Initialize a subcommand with argv"""
267 if '-h' in subc:
268 # requested help
269 self.print_description()
270 self.print_subcommands()
271 self.exit(0)
272 269 subapp,help = self.subcommands.get(subc, (None,None))
273 270 if subapp is None:
274 271 self.print_description()
@@ -289,15 +286,12 b' class Application(SingletonConfigurable):'
289 286 """Parse the command line arguments."""
290 287 argv = sys.argv[1:] if argv is None else argv
291 288
292 if self.subcommands:
293 # we have subcommands
294 if len(argv) == 0:
295 # none specified
296 self.print_description()
297 self.print_subcommands()
298 self.exit(1)
299
300 return self.initialize_subcommand(argv[0], argv[1:])
289 if self.subcommands and len(argv) > 0:
290 # we have subcommands, and one may have been specified
291 subc, subargv = argv[0], argv[1:]
292 if re.match(r'^\w(\-?\w)*$', subc):
293 # it's a subcommand, and *not* a flag or class parameter
294 return self.initialize_subcommand(subc, subargv)
301 295
302 296 if '-h' in argv or '--help' in argv or '--help-all' in argv:
303 297 self.print_description()
General Comments 0
You need to be logged in to leave comments. Login now