This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author forest
Recipients forest, jkloth, paul.j3, rhettinger
Date 2021-09-06.06:04:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <jnbbjgd58td03eh2ues55ktenupsd1mv75@4ax.com>
In-reply-to <qoabjg1man8p6fm4ukorgah9jcimv204qs@4ax.com>
Content
Here's another working example, allowing alternate separator strings (as
requested in #33389) via subclassing:

class OneMetavarHelpFormatter(argparse.HelpFormatter):
    """A formatter that avoids repeating action metavars.
    """
    OPTION_SEPARATOR = ', '
    METAVAR_SEPARATOR = ' '

    def _format_action_invocation(self, action):
        """Format action help without repeating the argument metavar
        """
        if not action.option_strings or action.nargs == 0:
            return super()._format_action_invocation(action)

        default = self._get_default_metavar_for_optional(action)
        args_string = self._format_args(action, default)
        options_string = self.OPTION_SEPARATOR.join(action.option_strings)
        return options_string + self.METAVAR_SEPARATOR + args_string
History
Date User Action Args
2021-09-06 06:04:10forestsetrecipients: + forest, rhettinger, jkloth, paul.j3
2021-09-06 06:04:10forestlinkissue45110 messages
2021-09-06 06:04:10forestcreate