summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 17:25:11 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-04-29 17:25:11 -0400
commit94c14045d62788fb123f4316867778fa5337adae (patch)
tree69bcc341d972b2420e5c144f6484b2502576e9d2
parent027ca037da952e9a4f7a1cd6ba5d92bc1ed1eea7 (diff)
downloadcliff-tablib-94c14045d62788fb123f4316867778fa5337adae.tar.gz
pass the App to the help action instead of passing just the command manager, since the app has the stout handle we want to use for printing the help
-rw-r--r--cliff/app.py2
-rw-r--r--cliff/help.py12
2 files changed, 7 insertions, 7 deletions
diff --git a/cliff/app.py b/cliff/app.py
index 119f78a..eec2d5c 100644
--- a/cliff/app.py
+++ b/cliff/app.py
@@ -90,7 +90,7 @@ class App(object):
'-h', '--help',
action=HelpAction,
nargs=0,
- default=self.command_manager, # tricky
+ default=self, # tricky
help="show this help message and exit",
)
parser.add_argument(
diff --git a/cliff/help.py b/cliff/help.py
index 391d8cc..2ac8bc4 100644
--- a/cliff/help.py
+++ b/cliff/help.py
@@ -12,15 +12,15 @@ class HelpAction(argparse.Action):
instance, passed in as the "default" value for the action.
"""
def __call__(self, parser, namespace, values, option_string=None):
- parser.print_help()
- print('')
- print('Commands:')
- command_manager = self.default
+ 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)
one_liner = cmd.get_description().split('\n')[0]
- print(' %-13s %s' % (name, one_liner))
+ app.stdout.write(' %-13s %s\n' % (name, one_liner))
sys.exit(0)
@@ -47,5 +47,5 @@ class HelpCommand(Command):
cmd_parser = cmd.get_parser(full_name)
else:
cmd_parser = self.get_parser(' '.join([self.app.NAME, 'help']))
- cmd_parser.parse_args(['--help'])
+ cmd_parser.print_help(self.app.stdout)
return 0