summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Berendt <berendt@b1-systems.de>2014-06-04 21:03:42 +0200
committerChristian Berendt <berendt@b1-systems.de>2014-07-16 13:51:39 +0200
commitd864c23aa84a437d726cd761646b684c520f0281 (patch)
treeae897e4778ad243ae5a4e528045e428612091847
parent5c8a85e3861c0e90ef63325956ca809edca5719a (diff)
downloadpython-ceilometerclient-d864c23aa84a437d726cd761646b684c520f0281.tar.gz
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
-rw-r--r--ceilometerclient/shell.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/ceilometerclient/shell.py b/ceilometerclient/shell.py
index 46a460c..baf31a1 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:])