replace default --help processor with one that includes the list of subcommands available
This commit is contained in:
parent
e5c6c4c918
commit
417c4f7bac
20
cliff/app.py
20
cliff/app.py
|
@ -23,6 +23,7 @@ class App(object):
|
||||||
self.parser = optparse.OptionParser(
|
self.parser = optparse.OptionParser(
|
||||||
description=description,
|
description=description,
|
||||||
version='%prog {}'.format(version),
|
version='%prog {}'.format(version),
|
||||||
|
add_help_option=False,
|
||||||
)
|
)
|
||||||
self.parser.disable_interspersed_args()
|
self.parser.disable_interspersed_args()
|
||||||
self.parser.add_option(
|
self.parser.add_option(
|
||||||
|
@ -31,8 +32,27 @@ class App(object):
|
||||||
dest='verbose',
|
dest='verbose',
|
||||||
help='Increase verbosity of output. Can be repeated.',
|
help='Increase verbosity of output. Can be repeated.',
|
||||||
)
|
)
|
||||||
|
self.parser.add_option(
|
||||||
|
'-h', action='help',
|
||||||
|
help="show this help message and exit",
|
||||||
|
)
|
||||||
|
self.parser.add_option(
|
||||||
|
'--help', action='callback',
|
||||||
|
callback=self.show_verbose_help,
|
||||||
|
help="show verbose help message and exit",
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def show_verbose_help(self, *args):
|
||||||
|
self.parser.print_help()
|
||||||
|
print('')
|
||||||
|
print('Commands:')
|
||||||
|
for name, ep in sorted(self.command_manager):
|
||||||
|
factory = ep.load()
|
||||||
|
cmd = factory(self, None)
|
||||||
|
print(' %-13s %s' % (name, cmd.get_description()))
|
||||||
|
raise SystemExit()
|
||||||
|
|
||||||
def run(self, argv):
|
def run(self, argv):
|
||||||
parsed_args, remainder = self.parser.parse_args(argv)
|
parsed_args, remainder = self.parser.parse_args(argv)
|
||||||
# FIXME(dhellmann): set up logging based on verbosity flag
|
# FIXME(dhellmann): set up logging based on verbosity flag
|
||||||
|
|
|
@ -24,6 +24,9 @@ class CommandManager(object):
|
||||||
self.commands[ep.name.replace('_', ' ')] = ep
|
self.commands[ep.name.replace('_', ' ')] = ep
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.commands.items())
|
||||||
|
|
||||||
def find_command(self, argv):
|
def find_command(self, argv):
|
||||||
"""Given an argument list, find a command and
|
"""Given an argument list, find a command and
|
||||||
return the processor and any remaining arguments.
|
return the processor and any remaining arguments.
|
||||||
|
|
|
@ -3,6 +3,7 @@ from cliff.command import Command
|
||||||
|
|
||||||
|
|
||||||
class Simple(Command):
|
class Simple(Command):
|
||||||
|
"A simple command that prints a message."
|
||||||
|
|
||||||
def run(self, parsed_args):
|
def run(self, parsed_args):
|
||||||
print 'hi!'
|
print 'hi!'
|
||||||
|
|
Loading…
Reference in New Issue