diff options
author | Zuul <zuul@review.opendev.org> | 2019-09-23 15:38:01 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-09-23 15:38:01 +0000 |
commit | a033aeb84befbb85b3c6490a0e30e977abc95256 (patch) | |
tree | cfdb6e8ffca29c8e4313552e2bdc90e2bc56ecb6 | |
parent | 6b6b1863ff757f07c73b1285dc6a2cb48a546f8e (diff) | |
parent | 584352dcd008d58c433136539b22a6ae9d6c45cc (diff) | |
download | cliff-a033aeb84befbb85b3c6490a0e30e977abc95256.tar.gz |
Merge "Stop wildcard importing argparse"
-rw-r--r-- | cliff/_argparse.py | 25 | ||||
-rw-r--r-- | cliff/command.py | 23 |
2 files changed, 24 insertions, 24 deletions
diff --git a/cliff/_argparse.py b/cliff/_argparse.py index 5358e72..1f1be0f 100644 --- a/cliff/_argparse.py +++ b/cliff/_argparse.py @@ -10,10 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. -"""Special argparse module that allows to bypass abbrev mode.""" +"""Overrides of standard argparse behavior.""" from __future__ import absolute_import -from argparse import * # noqa + import argparse import sys import warnings @@ -104,3 +104,24 @@ class _MutuallyExclusiveGroup(argparse._MutuallyExclusiveGroup): action, conflicting_actions, ) + + +class SmartHelpFormatter(argparse.HelpFormatter): + """Smart help formatter to output raw help message if help contain \n. + + Some command help messages maybe have multiple line content, the built-in + argparse.HelpFormatter wrap and split the content according to width, and + ignore \n in the raw help message, it merge multiple line content in one + line to output, that looks messy. SmartHelpFormatter keep the raw help + message format if it contain \n, and wrap long line like HelpFormatter + behavior. + """ + + def _split_lines(self, text, width): + lines = text.splitlines() if '\n' in text else [text] + wrap_lines = [] + for each_line in lines: + wrap_lines.extend( + super(SmartHelpFormatter, self)._split_lines(each_line, width) + ) + return wrap_lines diff --git a/cliff/command.py b/cliff/command.py index 760832b..c020edc 100644 --- a/cliff/command.py +++ b/cliff/command.py @@ -155,7 +155,7 @@ class Command(object): description=self.get_description(), epilog=self.get_epilog(), prog=prog_name, - formatter_class=_SmartHelpFormatter, + formatter_class=_argparse.SmartHelpFormatter, conflict_handler='ignore', ) for hook in self._hooks: @@ -221,24 +221,3 @@ class Command(object): if ret is not None: return_code = ret return return_code - - -class _SmartHelpFormatter(_argparse.HelpFormatter): - """Smart help formatter to output raw help message if help contain \n. - - Some command help messages maybe have multiple line content, the built-in - argparse.HelpFormatter wrap and split the content according to width, and - ignore \n in the raw help message, it merge multiple line content in one - line to output, that looks messy. SmartHelpFormatter keep the raw help - message format if it contain \n, and wrap long line like HelpFormatter - behavior. - """ - - def _split_lines(self, text, width): - lines = text.splitlines() if '\n' in text else [text] - wrap_lines = [] - for each_line in lines: - wrap_lines.extend( - super(_SmartHelpFormatter, self)._split_lines(each_line, width) - ) - return wrap_lines |