From d864c23aa84a437d726cd761646b684c520f0281 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 4 Jun 2014 21:03:42 +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: alarm-threshold-create Create a new alarm based on computed statistics. alarm-threshold-update Update an existing alarm based on computed statistics. alarm-update Update an existing alarm (Deprecated). example output after this patch: alarm-threshold-create Create a new alarm based on computed statistics. alarm-threshold-update Update an existing alarm based on computed statistics. alarm-update Update an existing alarm (Deprecated). Change-Id: I945e46bb9e0309b960e3322261d9d6ff9fa35b52 Closes-Bug: #1326471 --- ceilometerclient/shell.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ceilometerclient/shell.py b/ceilometerclient/shell.py index 46a460cc..baf31a14 100644 --- a/ceilometerclient/shell.py +++ b/ceilometerclient/shell.py @@ -396,6 +396,18 @@ class CeilometerShell(object): class HelpFormatter(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(HelpFormatter, self).add_arguments(actions) + def start_section(self, heading): # Title-case the headings heading = '%s%s' % (heading[0].upper(), heading[1:])