From a31cc3293eaeecf7494c226b2211fd0f219d4bea Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 4 Jun 2014 20:27:06 +0200 Subject: [PATCH] Calculate a suitable column width for positional arguments Overwrite the method add_arguments in the class OpenStackHelpFormatter to calculate a suitable columnt width (max_help_position) for the positional arguments. example output before this patch: ec2-credentials-create Create EC2-compatible credentials for user per tenant. ec2-credentials-delete Delete EC2-compatible credentials. ec2-credentials-get Display EC2-compatible credentials. ec2-credentials-list List EC2-compatible credentials for a user. example output after this patch: ec2-credentials-create Create EC2-compatible credentials for user per tenant. ec2-credentials-delete Delete EC2-compatible credentials. ec2-credentials-get Display EC2-compatible credentials. ec2-credentials-list List EC2-compatible credentials for a user. Change-Id: Ibd5d3502022d2afcfd4f57fef9a0bbf23d34b767 Closes-Bug: #1326471 --- keystoneclient/shell.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py index 30bd9a9f0..d19a61f01 100644 --- a/keystoneclient/shell.py +++ b/keystoneclient/shell.py @@ -437,6 +437,18 @@ class OpenStackIdentityShell(object): # I'm picky about my shell help. class OpenStackHelpFormatter(argparse.HelpFormatter): + INDENT_BEFORE_ARGUMENTS = 6 + MAX_WIDTH_ARGUMENTS = 32 + + def add_arguments(self, actions): + for action in filter(lambda x: not x.option_strings, actions): + for choice in action.choices: + length = len(choice) + self.INDENT_BEFORE_ARGUMENTS + if(length > self._max_help_position and + length <= self.MAX_WIDTH_ARGUMENTS): + self._max_help_position = length + super(OpenStackHelpFormatter, self).add_arguments(actions) + def start_section(self, heading): # Title-case the headings heading = '%s%s' % (heading[0].upper(), heading[1:])