diff options
author | Doug Hellmann <doug.hellmann@dreamhost.com> | 2012-06-20 17:27:08 -0400 |
---|---|---|
committer | Doug Hellmann <doug.hellmann@dreamhost.com> | 2012-06-20 17:27:08 -0400 |
commit | 83469ad81a27f0b264bd93904b2b172fd889cad9 (patch) | |
tree | 5767811612dbf0c0918b4d798bacc56cb5120283 /cliff | |
parent | 9bb0a4a13acfce6a0924514b883417875a1143dc (diff) | |
download | cliff-83469ad81a27f0b264bd93904b2b172fd889cad9.tar.gz |
Doc updates for API changes.1.0
Clean up docstrings.
Bump version to 1.0.
Change-Id: I1047c637ffed4ffac8bffbdaa1bddc56895716d9
Diffstat (limited to 'cliff')
-rw-r--r-- | cliff/app.py | 6 | ||||
-rw-r--r-- | cliff/command.py | 14 | ||||
-rw-r--r-- | cliff/help.py | 14 |
3 files changed, 27 insertions, 7 deletions
diff --git a/cliff/app.py b/cliff/app.py index 06c679f..bc0b65e 100644 --- a/cliff/app.py +++ b/cliff/app.py @@ -143,7 +143,11 @@ class App(object): self.interactive_mode = not remainder self.initialize_app(remainder) except Exception as err: - if self.options.debug: + if hasattr(self, 'options'): + debug = self.options.debug + else: + debug = True + if debug: LOG.exception(err) raise else: diff --git a/cliff/command.py b/cliff/command.py index e369988..1661313 100644 --- a/cliff/command.py +++ b/cliff/command.py @@ -23,7 +23,7 @@ class Command(object): return inspect.getdoc(self.__class__) or '' def get_parser(self, prog_name): - """Return an argparse.ArgumentParser. + """Return an :class:`argparse.ArgumentParser`. """ parser = argparse.ArgumentParser( description=self.get_description(), @@ -33,12 +33,18 @@ class Command(object): @abc.abstractmethod def take_action(self, parsed_args): - """Return a two-part tuple with a tuple of column names - and a tuple of values. + """Override to do something useful. """ def run(self, parsed_args): - """Do something useful. + """Invoked by the application when the command is run. + + Developers implementing commands should override + :meth:`take_action`. + + Developers creating new command base classes (such as + :class:`Lister` and :class:`ShowOne`) should override this + method to wrap :meth:`take_action`. """ self.take_action(parsed_args) return 0 diff --git a/cliff/help.py b/cliff/help.py index 49cfd16..9a7f848 100644 --- a/cliff/help.py +++ b/cliff/help.py @@ -1,4 +1,5 @@ import argparse +import logging import sys from .command import Command @@ -12,13 +13,22 @@ class HelpAction(argparse.Action): instance, passed in as the "default" value for the action. """ def __call__(self, parser, namespace, values, option_string=None): + log = logging.getLogger(__name__) app = self.default parser.print_help(app.stdout) app.stdout.write('\nCommands:\n') command_manager = app.command_manager for name, ep in sorted(command_manager): - factory = ep.load() - cmd = factory(self, None) + try: + factory = ep.load() + except Exception as err: + app.stdout.write('Could not load %r\n' % ep) + continue + try: + cmd = factory(self, None) + except Exception as err: + app.stdout.write('Could not instantiate %r: %s\n' % (ep, err)) + continue one_liner = cmd.get_description().split('\n')[0] app.stdout.write(' %-13s %s\n' % (name, one_liner)) sys.exit(0) |