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
This commit is contained in:
@@ -437,6 +437,18 @@ class OpenStackIdentityShell(object):
|
|||||||
|
|
||||||
# I'm picky about my shell help.
|
# I'm picky about my shell help.
|
||||||
class OpenStackHelpFormatter(argparse.HelpFormatter):
|
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):
|
def start_section(self, heading):
|
||||||
# Title-case the headings
|
# Title-case the headings
|
||||||
heading = '%s%s' % (heading[0].upper(), heading[1:])
|
heading = '%s%s' % (heading[0].upper(), heading[1:])
|
||||||
|
|||||||
Reference in New Issue
Block a user