當前位置: 首頁>>代碼示例>>Python>>正文


Python argparse.ONE_OR_MORE屬性代碼示例

本文整理匯總了Python中argparse.ONE_OR_MORE屬性的典型用法代碼示例。如果您正苦於以下問題:Python argparse.ONE_OR_MORE屬性的具體用法?Python argparse.ONE_OR_MORE怎麽用?Python argparse.ONE_OR_MORE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在argparse的用法示例。


在下文中一共展示了argparse.ONE_OR_MORE屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_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

示例2: _format_args

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_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

示例3: configure_app

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def configure_app(app, parser):
        parser.add_argument(
            'effects',
            nargs=argparse.ONE_OR_MORE,
            help='JSON-encoded effect schedules data files'
        )

        parser.add_argument(
            '--glucose',
            help='JSON-encoded glucose data file in reverse-chronological order'
        )

        parser.add_argument(
            '--momentum',
            help='JSON-encoded momentum effect schedule data file'
        ) 
開發者ID:loudnate,項目名稱:openaps-predict,代碼行數:18,代碼來源:__init__.py

示例4: _match_argument

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def _match_argument(self, action, arg_strings_pattern):
        # - https://github.com/streamlink/streamlink/issues/971
        # - https://bugs.python.org/issue9334

        # match the pattern for this action to the arg strings
        nargs_pattern = self._get_nargs_pattern(action)
        match = argparse._re.match(nargs_pattern, arg_strings_pattern)

        # if no match, see if we can emulate optparse and return the
        # required number of arguments regardless of their values
        if match is None:
            nargs = action.nargs if action.nargs is not None else 1
            if isinstance(nargs, numbers.Number) and len(arg_strings_pattern) >= nargs:
                return nargs

        # raise an exception if we weren't able to find a match
        if match is None:
            nargs_errors = {
                None: argparse._('expected one argument'),
                argparse.OPTIONAL: argparse._('expected at most one argument'),
                argparse.ONE_OR_MORE: argparse._('expected at least one argument'),
            }
            default = argparse.ngettext('expected %s argument',
                                        'expected %s arguments',
                                        action.nargs) % action.nargs
            msg = nargs_errors.get(action.nargs, default)
            raise argparse.ArgumentError(action, msg)

        # return the number of arguments matched
        return len(match.group(1)) 
開發者ID:streamlink,項目名稱:streamlink,代碼行數:32,代碼來源:argparser.py

示例5: _format_args

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_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

示例6: test_apcustom_narg_tuple_one_base

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def test_apcustom_narg_tuple_one_base():
    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(1,))
    assert arg.nargs == argparse.ONE_OR_MORE
    assert arg.nargs_range is None
    assert "arg [...]" in parser.format_help()

    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(1, 5))
    assert arg.nargs == argparse.ONE_OR_MORE
    assert arg.nargs_range == (1, 5)
    assert "arg{1..5}" in parser.format_help()


# noinspection PyUnresolvedReferences 
開發者ID:python-cmd2,項目名稱:cmd2,代碼行數:17,代碼來源:test_argparse_custom.py

示例7: test_apcustom_narg_tuple_other_ranges

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def test_apcustom_narg_tuple_other_ranges():

    # Test range with no upper bound on max
    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(2,))
    assert arg.nargs == argparse.ONE_OR_MORE
    assert arg.nargs_range == (2, constants.INFINITY)

    # Test finite range
    parser = Cmd2ArgumentParser()
    arg = parser.add_argument('arg', nargs=(2, 5))
    assert arg.nargs == argparse.ONE_OR_MORE
    assert arg.nargs_range == (2, 5) 
開發者ID:python-cmd2,項目名稱:cmd2,代碼行數:15,代碼來源:test_argparse_custom.py

示例8: __init__

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_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

示例9: mongolock_cli

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def mongolock_cli():
    @configure
    def main():
        parser = argparse.ArgumentParser(
            description="Run program, acquiring the lock in MongoDB"
        )
        parser.add_argument(
            "-l", "--lockname",
            help="Name of the lock",
            required=True
        )
        parser.add_argument(
            "-b", "--block",
            help="Block execution till lock will be available",
            action="store_true",
            default=False
        )
        parser.add_argument(
            "-t", "--timeout",
            help="Timeout for blocking",
            type=int,
            default=None
        )
        parser.add_argument(
            "command",
            help="Command to run",
            nargs=argparse.ONE_OR_MORE,
        )
        options = parser.parse_args()

        locked = lock.with_autoprolong_lock(
            options.lockname,
            block=options.block, timeout=options.timeout)

        with locked:
            pty.spawn(options.command)

    return main() 
開發者ID:Mirantis,項目名稱:ceph-lcm,代碼行數:40,代碼來源:cliutils.py

示例10: get_options

# 需要導入模塊: import argparse [as 別名]
# 或者: from argparse import ONE_OR_MORE [as 別名]
def get_options():
    parser = argparse.ArgumentParser(description="Verificator of Ceph version")

    parser.add_argument(
        "-t", "--type",
        default="deb",
        help="Type of the repository. Default is 'deb'."
    )
    parser.add_argument(
        "-c", "--orig-comps",
        default=["main"],
        nargs=argparse.ONE_OR_MORE,
        help="Repository names. 'main' is the default one."
    )
    parser.add_argument(
        "-u", "--repo-url",
        help="URL of the repository"
    )
    parser.add_argument(
        "-d", "--distro-source",
        default="",
        help="release of the repository."
    )
    parser.add_argument(
        "-p", "--package-name",
        default="ceph-common",
        help="package name to verify."
    )
    parser.add_argument(
        "--no-verify-packages",
        action="store_true",
        default=False,
        help="skip package version verification."
    )
    parser.add_argument(
        "--no-verify-installed-versions",
        action="store_true",
        default=False,
        help="skip installed version verification."
    )
    parser.add_argument(
        "--no-verify-repo-candidate",
        action="store_true",
        default=False,
        help="skip verification of remote APT repo."
    )

    parser.add_argument(
        "directory",
        help="directory with fetched files."
    )
    parser.add_argument(
        "raw_deb_url",
        nargs=argparse.OPTIONAL,
        help="raw repo string to use. If set, then -u, -c, -d and -t "
             "are ignored."
    )

    return parser.parse_args() 
開發者ID:Mirantis,項目名稱:ceph-lcm,代碼行數:61,代碼來源:ceph_verify.py


注:本文中的argparse.ONE_OR_MORE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。