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