diff --git a/cliff/app.py b/cliff/app.py index 37321893..2e982a89 100644 --- a/cliff/app.py +++ b/cliff/app.py @@ -23,6 +23,7 @@ class App(object): self.parser = optparse.OptionParser( description=description, version='%prog {}'.format(version), + add_help_option=False, ) self.parser.disable_interspersed_args() self.parser.add_option( @@ -31,8 +32,27 @@ class App(object): dest='verbose', 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 + 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): parsed_args, remainder = self.parser.parse_args(argv) # FIXME(dhellmann): set up logging based on verbosity flag diff --git a/cliff/commandmanager.py b/cliff/commandmanager.py index 16420eac..a7e6dddf 100644 --- a/cliff/commandmanager.py +++ b/cliff/commandmanager.py @@ -24,6 +24,9 @@ class CommandManager(object): self.commands[ep.name.replace('_', ' ')] = ep return + def __iter__(self): + return iter(self.commands.items()) + def find_command(self, argv): """Given an argument list, find a command and return the processor and any remaining arguments. diff --git a/demoapp/cliffdemo/simple.py b/demoapp/cliffdemo/simple.py index 4416814b..ccfd7ef7 100644 --- a/demoapp/cliffdemo/simple.py +++ b/demoapp/cliffdemo/simple.py @@ -3,6 +3,7 @@ from cliff.command import Command class Simple(Command): + "A simple command that prints a message." def run(self, parsed_args): print 'hi!'