summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@gmail.com>2012-04-20 22:20:17 -0700
committerDoug Hellmann <doug.hellmann@gmail.com>2012-04-20 22:20:17 -0700
commit417c4f7bac78450d4f00ae19e0efafd267bc6fbb (patch)
treed0a6d7827ea18b347eb805d14a139be30a0f369f
parente5c6c4c918484c6bb422cbeb8f0af329e4c706fd (diff)
downloadcliff-tablib-417c4f7bac78450d4f00ae19e0efafd267bc6fbb.tar.gz
replace default --help processor with one that includes the list of subcommands available
-rw-r--r--cliff/app.py20
-rw-r--r--cliff/commandmanager.py3
-rw-r--r--demoapp/cliffdemo/simple.py1
3 files changed, 24 insertions, 0 deletions
diff --git a/cliff/app.py b/cliff/app.py
index 3732189..2e982a8 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 16420ea..a7e6ddd 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 4416814..ccfd7ef 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!'