How to use the configargparse.HelpFormatter function in ConfigArgParse

To help you get started, we’ve selected a few ConfigArgParse examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arendst / Tasmota / tools / decode-config.py View on Github external
if len(header)>0:
            return header[0].rstrip()
        return ''

    def contenttype(self):
        for item in str(self.contents).split('\n'):
            ditem = item.split(":")
            if ditem[0].strip().lower()=='content-type' and len(ditem)>1:
                return ditem[1].strip()
        return ''

    def __str__(self):
        return self.contents


class CustomHelpFormatter(configargparse.HelpFormatter):
    """
    Class for customizing the help output
    """

    def _format_action_invocation(self, action):
        """
        Reformat multiple metavar output
            -d , --device , --host 
        to single output
            -d, --device, --host 
        """

        orgstr = configargparse.HelpFormatter._format_action_invocation(self, action)
        if orgstr and orgstr[0] != '-': # only optional arguments
            return orgstr
        res = getattr(action, '_formatted_action_invocation', None)
github rr- / dotfiles / opt / booru-toolkit / booru_toolkit / cli.py View on Github external
def make_arg_parser(
    description: str, plugins: List[PluginBase]
) -> configargparse.Parser:
    class CustomHelpFormatter(configargparse.HelpFormatter):
        def _format_action_invocation(
            self, action: configargparse.Action
        ) -> str:
            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)
            return ", ".join(action.option_strings) + " " + args_string

    class PluginAction(configargparse.Action):
        def __call__(
            self,
            parser: configargparse.Parser,
            args: configargparse.Namespace,
            values: Any,
            option_string=None,