当前位置: 首页>>代码示例>>Python>>正文


Python argparse.HelpFormatter方法代码示例

本文整理汇总了Python中argparse.HelpFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python argparse.HelpFormatter方法的具体用法?Python argparse.HelpFormatter怎么用?Python argparse.HelpFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在argparse的用法示例。


在下文中一共展示了argparse.HelpFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_arguments

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def get_arguments(self):
        ''' Returns parser.args() containing all program arguments '''

        parser = argparse.ArgumentParser(usage=argparse.SUPPRESS,
                formatter_class=lambda prog: argparse.HelpFormatter(
                    prog, max_help_position=80, width=130))

        self._add_global_args(parser.add_argument_group(Color.s('{C}SETTINGS{W}')))
        self._add_wep_args(parser.add_argument_group(Color.s('{C}WEP{W}')))
        self._add_wpa_args(parser.add_argument_group(Color.s('{C}WPA{W}')))
        self._add_wps_args(parser.add_argument_group(Color.s('{C}WPS{W}')))
        self._add_pmkid_args(parser.add_argument_group(Color.s('{C}PMKID{W}')))
        self._add_eviltwin_args(parser.add_argument_group(Color.s('{C}EVIL TWIN{W}')))
        self._add_command_args(parser.add_argument_group(Color.s('{C}COMMANDS{W}')))

        return parser.parse_args() 
开发者ID:nuncan,项目名称:wifite2mod,代码行数:18,代码来源:args.py

示例2: main

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def main(argv):
    def formatter(prog):
        return argparse.HelpFormatter(prog, max_help_position=100, width=200)

    argparser = argparse.ArgumentParser('NLI Client', formatter_class=formatter)

    argparser.add_argument('s1', action='store', type=str)
    argparser.add_argument('s2', action='store', type=str)
    argparser.add_argument('--url', '-u', action='store', type=str, default='http://127.0.0.1:8889/v1/nli')

    args = argparser.parse_args(argv)

    sentence1 = args.s1
    sentence2 = args.s2

    url = args.url

    prediction = call_service(url=url, sentence1=sentence1, sentence2=sentence2)
    print(prediction) 
开发者ID:uclnlp,项目名称:inferbeddings,代码行数:21,代码来源:nli-query-cli.py

示例3: main

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def main(argv):
    def formatter(prog):
        return argparse.HelpFormatter(prog, max_help_position=100, width=200)

    argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs',
                                        formatter_class=formatter)
    argparser.add_argument('triples', type=str, help='File containing triples')
    argparser.add_argument('entities', type=str, help='File containing entities')

    args = argparser.parse_args(argv)

    triples_path = args.triples
    entities_path = args.entities

    triples = read_triples(triples_path)

    with iopen(entities_path, mode='r') as f:
        entities = set([line.strip() for line in f.readlines()])

    for (s, p, o) in triples:
        if s in entities and o in entities:
            print("%s\t%s\t%s" % (s, p, o)) 
开发者ID:uclnlp,项目名称:inferbeddings,代码行数:24,代码来源:filter.py

示例4: _find_actions

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hypen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command, help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)
            subparser.add_argument('-h', '--help', action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
开发者ID:nttcom,项目名称:eclcli,代码行数:21,代码来源:shell.py

示例5: _find_actions

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _find_actions(self, subparsers, actions_module):
        for attr in (a for a in dir(actions_module) if a.startswith('do_')):
            # I prefer to be hyphen-separated instead of underscores.
            command = attr[3:].replace('_', '-')
            callback = getattr(actions_module, attr)
            desc = callback.__doc__ or ''
            help = desc.strip().split('\n')[0]
            arguments = getattr(callback, 'arguments', [])

            subparser = subparsers.add_parser(command,
                                              help=help,
                                              description=desc,
                                              add_help=False,
                                              formatter_class=HelpFormatter)
            subparser.add_argument('-h', '--help',
                                   action='help',
                                   help=argparse.SUPPRESS)
            self.subcommands[command] = subparser
            for (args, kwargs) in arguments:
                subparser.add_argument(*args, **kwargs)
            subparser.set_defaults(func=callback) 
开发者ID:nttcom,项目名称:eclcli,代码行数:23,代码来源:shell.py

示例6: download_parser

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def download_parser(description):
    class SortedHelpFormatter(HelpFormatter):
        def add_arguments(self, actions):
            actions = sorted(actions, key=attrgetter("option_strings"))
            super(SortedHelpFormatter, self).add_arguments(actions)

    parser = ArgumentParser(
        description=description, formatter_class=SortedHelpFormatter
    )
    parser.add_argument("--force", action="store_true", help="override existing files")
    parser.add_argument(
        "--formats", nargs="+", metavar="FORMAT", help="ebook formats (epub, mobi, pdf)"
    )
    parser.add_argument(
        "--with-code-files", action="store_true", help="download code files"
    )
    return parser 
开发者ID:bogdal,项目名称:freepacktbook,代码行数:19,代码来源:__init__.py

示例7: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(
        self, add_blink_args=True, add_model_args=False, 
        description='BLINK parser',
    ):
        super().__init__(
            description=description,
            allow_abbrev=False,
            conflict_handler='resolve',
            formatter_class=argparse.HelpFormatter,
            add_help=add_blink_args,
        )
        self.blink_home = os.path.dirname(
            os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
        )
        os.environ['BLINK_HOME'] = self.blink_home

        self.add_arg = self.add_argument

        self.overridable = {}

        if add_blink_args:
            self.add_blink_args()
        if add_model_args:
            self.add_model_args() 
开发者ID:facebookresearch,项目名称:BLINK,代码行数:26,代码来源:params.py

示例8: _split_lines

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
        if text.startswith('R|'):
            lines = text[2:].splitlines()
            offsets = [re.match("^[ \t]*", l).group(0) for l in lines]
            wrapped = []
            for i in range(len(lines)):
                li = lines[i]
                o = offsets[i]
                ol = len(o)
                init_wrap = argparse._textwrap.fill(li, width).splitlines()
                first = init_wrap[0]
                rest = "\n".join(init_wrap[1:])
                rest_wrap = argparse._textwrap.fill(rest, width - ol).splitlines()
                offset_lines = [o + wl for wl in rest_wrap]
                wrapped = wrapped + [first] + offset_lines
            return wrapped
        return argparse.HelpFormatter._split_lines(self, text, width) 
开发者ID:neuropoly,项目名称:spinalcordtoolbox,代码行数:19,代码来源:utils.py

示例9: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(self, *args, group_name=None, **kwargs):
        super().__init__(*args, formatter_class=HelpFormatter, add_help=False, **kwargs)
        self.add_argument(
            '--help', dest='help', action='store_true', default=False,
            help='Show this help message and exit.'
        )
        self._optionals.title = 'Options'
        if group_name is None:
            self.epilog = (
                f"Run 'lbrynet COMMAND --help' for more information on a command or group."
            )
        else:
            self.epilog = (
                f"Run 'lbrynet {group_name} COMMAND --help' for more information on a command."
            )
            self.set_defaults(group=group_name, group_parser=self) 
开发者ID:lbryio,项目名称:lbry-sdk,代码行数:18,代码来源:cli.py

示例10: get_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def get_args():
    parser = argparse.ArgumentParser( prog="primefaces.py",
                      formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=50),
                      epilog= '''
                       This script exploits an expression language remote code execution flaw in the Primefaces JSF framework.
                       Primefaces versions prior to 5.2.21, 5.3.8 or 6.0 are vulnerable to a padding oracle attack, 
                       due to the use of weak crypto and default encryption password and salt.
                      ''')

    parser.add_argument("target", help="Target Host")
    parser.add_argument("-pw", "--password", default="primefaces", help="Primefaces Password (Default = primefaces")
    parser.add_argument("-pt", "--path", default="/javax.faces.resource/dynamiccontent.properties.xhtml", help="Path to dynamiccontent.properties (Default = /javax.faces.resource/dynamiccontent.properties.xhtml)")
    parser.add_argument("-c", "--cmd", default="whoami", help="Command to execute. (Default = whoami)")
    parser.add_argument("-px", "--proxy", default="", help="Configure a proxy in the format http://127.0.0.1:8080/ (Default = None)")
    parser.add_argument("-ck", "--cookie", default="", help="Configure a cookie in the format 'COOKIE=VALUE; COOKIE2=VALUE2;' (Default = None)")
    parser.add_argument("-o", "--oracle", default="0", help="Exploit the target with Padding Oracle. Use 1 to activate. (Default = 0) (SLOW)")
    parser.add_argument("-pl", "--payload", default="", help="EL Encrypted payload. That function is meant to be used with the Padding Oracle generated payload. (Default = None) ")
    args = parser.parse_args()
    return args 
开发者ID:pimps,项目名称:CVE-2017-1000486,代码行数:21,代码来源:primefaces.py

示例11: _split_lines

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
        """ Split the given text by the given display width.

        If the text is not prefixed with "R|" then the standard
        :func:`argparse.HelpFormatter._split_lines` function is used, otherwise raw
        formatting is processed,

        Parameters
        ----------
        text: str
            The help text that is to be formatted for display
        width: int
            The display width, in characters, for the help text
        """
        if text.startswith("R|"):
            text = self._whitespace_matcher_limited.sub(' ', text).strip()[2:]
            output = list()
            for txt in text.splitlines():
                indent = ""
                if txt.startswith("L|"):
                    indent = "    "
                    txt = "  - {}".format(txt[2:])
                output.extend(textwrap.wrap(txt, width, subsequent_indent=indent))
            return output
        return argparse.HelpFormatter._split_lines(self, text, width) 
开发者ID:deepfakes,项目名称:faceswap,代码行数:27,代码来源:args.py

示例12: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(self, prog=''):
        argparse.HelpFormatter.__init__(
            self, prog, max_help_position=100, width=150) 
开发者ID:Kosat,项目名称:telegram-messages-dump,代码行数:5,代码来源:chat_dump_settings.py

示例13: _format_action_invocation

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _format_action_invocation(self, action):
        orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
        if orgstr and orgstr[0] != "-":  # only optional arguments
            return orgstr
        res = getattr(action, "_formatted_action_invocation", None)
        if res:
            return res
        options = orgstr.split(", ")
        if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2):
            # a shortcut for '-h, --help' or '--abc', '-a'
            action._formatted_action_invocation = orgstr
            return orgstr
        return_list = []
        option_map = getattr(action, "map_long_option", {})
        if option_map is None:
            option_map = {}
        short_long = {}
        for option in options:
            if len(option) == 2 or option[2] == " ":
                continue
            if not option.startswith("--"):
                raise ArgumentError(
                    'long optional argument without "--": [%s]' % (option), self
                )
            xxoption = option[2:]
            if xxoption.split()[0] not in option_map:
                shortened = xxoption.replace("-", "")
                if shortened not in short_long or len(short_long[shortened]) < len(
                    xxoption
                ):
                    short_long[shortened] = xxoption
        # now short_long has been filled out to the longest with dashes
        # **and** we keep the right option ordering from add_argument
        for option in options:
            if len(option) == 2 or option[2] == " ":
                return_list.append(option)
            if option[2:] == short_long.get(option.replace("-", "")):
                return_list.append(option.replace(" ", "=", 1))
        action._formatted_action_invocation = ", ".join(return_list)
        return action._formatted_action_invocation 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:42,代码来源:argparsing.py

示例14: test_parser

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def test_parser(self):
        parser = argparse.ArgumentParser(prog='PROG')
        string = (
            "ArgumentParser(prog='PROG', usage=None, description=None, "
            "version=None, formatter_class=%r, conflict_handler='error', "
            "add_help=True)" % argparse.HelpFormatter)
        self.assertStringEqual(parser, string)

# ===============
# Namespace tests
# =============== 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_argparse.py

示例15: _split_lines

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
        if text.startswith('R|'):
            return text[2:].splitlines()
        return argparse.HelpFormatter._split_lines(self, text, width) 
开发者ID:mrts,项目名称:ask-jira,代码行数:6,代码来源:smart_argparse_formatter.py


注:本文中的argparse.HelpFormatter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。