From 3d423a35d0d97bdd8bcabd352eded5cda51a5a67 Mon Sep 17 00:00:00 2001 From: Gary Kotton <gkotton@redhat.com> Date: Wed, 5 Dec 2012 12:17:00 +0000 Subject: [PATCH] Ensures that help alignment is not hard coded Fixes bug 1086770 Change-Id: I6fa3edea83783e274d78e0c0195bca69d63b6e04 --- quantumclient/shell.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/quantumclient/shell.py b/quantumclient/shell.py index 34f1a99..0beae19 100644 --- a/quantumclient/shell.py +++ b/quantumclient/shell.py @@ -141,6 +141,8 @@ class HelpAction(argparse.Action): instance, passed in as the "default" value for the action. """ def __call__(self, parser, namespace, values, option_string=None): + outputs = [] + max_len = 0 app = self.default parser.print_help(app.stdout) app.stdout.write('\nCommands for API v%s:\n' % app.api_version) @@ -149,7 +151,10 @@ class HelpAction(argparse.Action): factory = ep.load() cmd = factory(self, None) one_liner = cmd.get_description().split('\n')[0] - app.stdout.write(' %-25s %s\n' % (name, one_liner)) + outputs.append((name, one_liner)) + max_len = max(len(name), max_len) + for (name, one_liner) in outputs: + app.stdout.write(' %s %s\n' % (name.ljust(max_len), one_liner)) sys.exit(0)