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


Python argparse.ZERO_OR_MORE属性代码示例

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


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

示例1: init_parser

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def init_parser(self):
        """
        Init command line parser
        :return:
        """
        parser = argparse.ArgumentParser(description='ROCA TLS Fingerprinter')

        parser.add_argument('--debug', dest='debug', default=False, action='store_const', const=True,
                            help='Debugging logging')

        parser.add_argument('--dump', dest='dump', default=False, action='store_const', const=True,
                            help='Dump all processed info')

        parser.add_argument('--flatten', dest='flatten', default=False, action='store_const', const=True,
                            help='Flatten the dump')

        parser.add_argument('--indent', dest='indent', default=False, action='store_const', const=True,
                            help='Indent the dump')

        parser.add_argument('--hosts', dest='hosts', default=False, action='store_const', const=True,
                            help='Arguments are host names not file names')

        parser.add_argument('files', nargs=argparse.ZERO_OR_MORE, default=[],
                            help='files to process')
        return parser 
开发者ID:crocs-muni,项目名称:roca,代码行数:27,代码来源:detect_tls.py

示例2: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def __init__(self, option_strings, nargs=1, dest='vmnames', help=None,
                 **kwargs):
        if help is None:
            if nargs == argparse.OPTIONAL:
                help = 'at most one domain name'
            elif nargs == 1:
                help = 'a domain name'
            elif nargs == argparse.ZERO_OR_MORE:
                help = 'zero or more domain names'
            elif nargs == argparse.ONE_OR_MORE:
                help = 'one or more domain names'
            elif nargs > 1:
                help = '%s domain names' % nargs
            else:
                raise argparse.ArgumentError(
                    nargs, "Passed unexpected value {!s} as {!s} nargs ".format(
                        nargs, dest))

        super(VmNameAction, self).__init__(option_strings, dest=dest, help=help,
                                           nargs=nargs, **kwargs) 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:22,代码来源:__init__.py

示例3: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
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 \
                    not isinstance(type(action.default), bool):
                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 
开发者ID:Ecogenomics,项目名称:GTDBTk,代码行数:21,代码来源:custom_help_formatter.py

示例4: test_apcustom_narg_tuple_zero_base

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def test_apcustom_narg_tuple_zero_base():
    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(0,))
    assert arg.nargs == argparse.ZERO_OR_MORE
    assert arg.nargs_range is None
    assert "[arg [...]]" in parser.format_help()

    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(0, 1))
    assert arg.nargs == argparse.OPTIONAL
    assert arg.nargs_range is None
    assert "[arg]" in parser.format_help()

    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(0, 3))
    assert arg.nargs == argparse.ZERO_OR_MORE
    assert arg.nargs_range == (0, 3)
    assert "arg{0..3}" in parser.format_help()


# noinspection PyUnresolvedReferences 
开发者ID:python-cmd2,项目名称:cmd2,代码行数:23,代码来源:test_argparse_custom.py

示例5: _format_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _format_args(self, action, default_metavar) -> str:
        get_metavar = self._metavar_formatter(action, default_metavar)
        # Begin cmd2 customization (less verbose)
        nargs_range = getattr(action, ATTR_NARGS_RANGE, None)

        if nargs_range is not None:
            if nargs_range[1] == constants.INFINITY:
                range_str = '{}+'.format(nargs_range[0])
            else:
                range_str = '{}..{}'.format(nargs_range[0], nargs_range[1])

            result = '{}{{{}}}'.format('%s' % get_metavar(1), range_str)
        elif action.nargs == ZERO_OR_MORE:
            result = '[%s [...]]' % get_metavar(1)
        elif action.nargs == ONE_OR_MORE:
            result = '%s [...]' % get_metavar(1)
        elif isinstance(action.nargs, int) and action.nargs > 1:
            result = '{}{{{}}}'.format('%s' % get_metavar(1), action.nargs)
        # End cmd2 customization
        else:
            result = super()._format_args(action, default_metavar)
        return result


# noinspection PyCompatibility 
开发者ID:python-cmd2,项目名称:cmd2,代码行数:27,代码来源:argparse_custom.py

示例6: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
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 type(action.default) != bool:
                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 
开发者ID:jtamames,项目名称:SqueezeMeta,代码行数:18,代码来源:custom_help_formatter.py

示例7: prepare_playbook_plugin

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def prepare_playbook_plugin():
    @configure
    def main():
        parser = argparse.ArgumentParser(
            description="Prepare playbook plugins"
        )
        parser.add_argument(
            "plugin_name",
            nargs=argparse.ZERO_OR_MORE,
            default=[],
            help="Namespace of plugin to prepare. Empty means all plugins"
        )
        args = parser.parse_args()

        plugs = plugins.get_playbook_plugins()
        if args.plugin_name:
            plugs = {k: v for k, v in plugs.items() if k in args.plugin_name}
        plugs = {k: v() for k, v in plugs.items()}

        for name, plug in sorted(plugs.items()):
            LOG.info("Prepare plugin %s", name)
            plug.prepare_plugin()

    return main() 
开发者ID:Mirantis,项目名称:ceph-lcm,代码行数:26,代码来源:cliutils.py

示例8: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        help = action.help
        if not action.default:
            return help
        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:
                    help += ' (default: %(default)s)'
        return help 
开发者ID:thomasahle,项目名称:fastchess,代码行数:12,代码来源:tune.py

示例9: _format_args

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _format_args(self, action, default_metavar) -> str:
        get_metavar = self._metavar_formatter(action, default_metavar)
        # Begin cmd2 customization (less verbose)
        if isinstance(action, _RangeAction) and \
                action.nargs_min is not None and action.nargs_max is not None:
            result = '{}{{{}..{}}}'.format('%s' % get_metavar(1), action.nargs_min, action.nargs_max)
        elif action.nargs == ZERO_OR_MORE:
            result = '[%s [...]]' % get_metavar(1)
        elif action.nargs == ONE_OR_MORE:
            result = '%s [...]' % get_metavar(1)
        # End cmd2 customization
        else:
            result = super()._format_args(action, default_metavar)
        return result 
开发者ID:TuuuNya,项目名称:WebPocket,代码行数:16,代码来源:argparse_completer.py

示例10: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        help = action.help
        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:
                    help += ' (default: %(default)s)'
        if (
            hasattr(action, 'recommended')
            and action.recommended
            and action.recommended != action.default
        ):
            help += '(recommended: %(recommended)s)'
            help = help.replace(')(recommended', ', recommended')
        return help 
开发者ID:facebookresearch,项目名称:ParlAI,代码行数:17,代码来源:params.py

示例11: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        help_text = action.help
        if '%(default)' not in action.help and action.default is not argparse.SUPPRESS:
            if action.option_strings or action.nargs in [argparse.OPTIONAL, argparse.ZERO_OR_MORE]:
                if (
                        (not isinstance(action.default, bool) and isinstance(action.default, int))
                        or (isinstance(action.default, str) and action.default)
                ):
                    help_text += ' (default: %(default)s)'
        return help_text 
开发者ID:aiven,项目名称:aiven-client,代码行数:12,代码来源:argx.py

示例12: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        self.default = None

        if action.default not in (None, argparse.SUPPRESS):
            if action.option_strings or action.nargs in (argparse.OPTIONAL, argparse.ZERO_OR_MORE):
                self.default = self.__format_map.get(action.dest, lambda s: s)(action.default)

        return action.help 
开发者ID:BranislavBajuzik,项目名称:ColorWallpaper,代码行数:10,代码来源:CLI.py

示例13: __init__

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def __init__(self, arg_action: argparse.Action) -> None:
        self.action = arg_action
        self.min = None
        self.max = None
        self.count = 0
        self.is_remainder = (self.action.nargs == argparse.REMAINDER)

        # Check if nargs is a range
        nargs_range = getattr(self.action, ATTR_NARGS_RANGE, None)
        if nargs_range is not None:
            self.min = nargs_range[0]
            self.max = nargs_range[1]

        # Otherwise check against argparse types
        elif self.action.nargs is None:
            self.min = 1
            self.max = 1
        elif self.action.nargs == argparse.OPTIONAL:
            self.min = 0
            self.max = 1
        elif self.action.nargs == argparse.ZERO_OR_MORE or self.action.nargs == argparse.REMAINDER:
            self.min = 0
            self.max = constants.INFINITY
        elif self.action.nargs == argparse.ONE_OR_MORE:
            self.min = 1
            self.max = constants.INFINITY
        else:
            self.min = self.action.nargs
            self.max = self.action.nargs


# noinspection PyProtectedMember 
开发者ID:python-cmd2,项目名称:cmd2,代码行数:34,代码来源:argparse_completer.py

示例14: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        """
        Appends the default argument value to the help string for non-required args that have default values.

        This implementation is loosely based off of the argparse.ArgumentDefaultsHelpFormatter.
        """
        help_string = action.help
        if not action.required:
            if action.default not in (argparse.SUPPRESS, None):
                defaulting_nargs = [argparse.OPTIONAL, argparse.ZERO_OR_MORE]
                if action.option_strings or action.nargs in defaulting_nargs:
                    # using old string formatting style here because argparse internals use that
                    help_string += ' (default: %(default)s)'
        return help_string 
开发者ID:box,项目名称:ClusterRunner,代码行数:16,代码来源:argument_parsing.py

示例15: _get_help_string

# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import ZERO_OR_MORE [as 别名]
def _get_help_string(self, action):
        '''
        This module was taken from the RawDescriptionHelpFormatter class
        within argparse.  It deals with the formatting of the description string
        and allows properly formatted descriptions ot be printed without line
        wrapping.
        '''
        help = action.help
        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:
                    help += ' (default: %(default)s)'
        return help 
开发者ID:BD2KGenomics,项目名称:protect,代码行数:16,代码来源:pipelineWrapper.py


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