Commit 2895142d authored by Hugo Posnic's avatar Hugo Posnic

Simplify custom help formatter

parent 91644164
......@@ -24,46 +24,18 @@ class CustomHelpFormatter(argparse.HelpFormatter):
https://github.com/Ecogenomics/mingle/blob/master/mingle/custom_help_formatter.py
"""
def _split_lines(self, text, width):
"""Split lines"""
return text.splitlines()
def _get_help_string(self, action):
"""Place default value in help string."""
h = action.help
if "%(default)" not in action.help:
if action.default != "" and action.default != [] and action.default is not None and action.default is not False:
if action.default is not argparse.SUPPRESS:
defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
if action.option_strings or action.nargs in defaulting_nargs:
if "\n" in h:
lines = h.splitlines()
lines[0] += " (default: %(default)s)"
h = "\n".join(lines)
else:
h += " (default: %(default)s)"
return h
def _fill_text(self, text, width, indent):
"""Permit multiple line descriptions."""
return "".join([indent + line for line in text.splitlines(True)])
def _format_action_invocation(self, action):
"""Removes duplicate ALLCAPS with positional arguments."""
if not action.option_strings:
default = self._get_default_metavar_for_positional(action)
metavar, = self._metavar_formatter(action, default)(1)
return metavar
else:
parts = []
# if the Optional doesn't take a value, format is:
# -s, --long
if action.nargs == 0:
parts.extend(action.option_strings)
# if the Optional takes a value, format is:
# -s ARGS, --long ARGS
else:
......@@ -73,13 +45,4 @@ class CustomHelpFormatter(argparse.HelpFormatter):
parts.append(option_string)
return "%s %s" % (", ".join(parts), args_string)
return ", ".join(parts)
def _get_default_metavar_for_optional(self, action):
"""Get default metavar for optional"""
return action.dest.upper()
def _get_default_metavar_for_positional(self, action):
"""get default metavar for positional"""
return action.dest
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment