CommandLineReport: simplification and bug fix in option display

svn: r12836
This commit is contained in:
Gerald Britton 2009-07-24 18:05:07 +00:00
parent 72b0b7361c
commit 06171f8488

View File

@ -65,6 +65,7 @@ def _validate_options(options, dbase):
dbase: the database the options will be applied to dbase: the database the options will be applied to
""" """
if not hasattr(options, "menu"): if not hasattr(options, "menu"):
print 'no menu'
return return
menu = options.menu menu = options.menu
@ -360,30 +361,25 @@ class CommandLineReport(object):
elif self.show == 'all': elif self.show == 'all':
print " Available options:" print " Available options:"
for key in self.options_dict: for key in self.options_dict:
if key in self.options_dict: if key in self.options_help:
opt = self.options_help[key]
# Make the output nicer to read, assume that tab has 8 spaces # Make the output nicer to read, assume that tab has 8 spaces
if len(key) < 10: tabs = '\t' if len(key) < 10 else '\t'*2
print " %s\t\t%s (%s)" % (key, print " %s%s%s (%s)" % (key, tabs, opt[1], opt[0])
self.options_help[key][1],
self.options_help[key][0])
else:
print " %s\t%s (%s)" % (key,
self.options_help[key][1],
self.options_help[key][0])
else: else:
print " %s" % key print " %s" % key
print " Use 'show=option' to see description and acceptable values" print " Use 'show=option' to see description and acceptable values"
elif self.show in self.options_dict: elif self.show in self.options_help:
print ' %s%s\t%s' % (self.show, opt = self.options_help[self.show]
self.options_help[self.show][0], tabs = '\t' if len(self.show) < 10 else '\t'*2
self.options_help[self.show][1]) print ' %s%s%s%s' % (self.show, tabs, opt[0], opt[1])
print " Available values are:" print " Available values are:"
vals = self.options_help[self.show][2] vals = opt[2]
if isinstance(vals, (list, tuple)): if isinstance(vals, (list, tuple)):
for val in vals: for val in vals:
print " %s" % val print " %s" % val
else: else:
print " %s" % self.options_help[self.show][2] print " %s" % opt[2]
else: else:
#there was a show option given, but the option is invalid #there was a show option given, but the option is invalid