def formatter_factory(show_defaults=True):
"""Formatter factory"""
def get_help_string(self, action):
lhelp = action.help
if isinstance(show_defaults, (list, tuple)):
if "-" + action.dest in show_defaults:
return lhelp
if '%(default)' not in action.help:
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:
lhelp += ' (default: %(default)s)'
return lhelp
def default_help_string(self, action):
return action.help
if show_defaults is True:
ARPIFormatter._get_help_string = classmethod(get_help_string)
else:
ARPIFormatter._get_help_string = classmethod(default_help_string)
return ARPIFormatter
评论列表
文章目录