Python argparse.ONE_OR_MORE() Examples

The following are code examples for showing how to use argparse.ONE_OR_MORE(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: CSB   Author: csb-toolbox   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def add_array_argument(self, name, type, help, choices=None):
        """
        Same as L{self.add_positional_argument()}, but allow unlimited number
        of values to be specified on the command line.
        
        @param name: name of the argument (used in help only)
        @type name: str
        @param type: argument data type
        @type type: type (type factory callable)
        @param help: help text
        @type help: str
        @param choices: list of allowed argument values
        @type choices: tuple
        """
        self._add(ArgHandler.Type.POSITIONAL, name, None,
                  type=type, help=help, choices=choices, nargs=argparse.ONE_OR_MORE) 
Example 2
Project: qubes-core-admin-client   Author: QubesOS   File: __init__.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 3
Project: qubes-core-admin-client   Author: QubesOS   File: __init__.py    (license) View Source Project 6 votes vote down vote up
def __init__(self, option_strings, nargs=1, dest='vmnames', help=None,
                 **kwargs):
        # pylint: disable=redefined-builtin
        if help is None:
            if nargs == argparse.OPTIONAL:
                help = 'at most one running domain'
            elif nargs == 1:
                help = 'running domain name'
            elif nargs == argparse.ZERO_OR_MORE:
                help = 'zero or more running domains'
            elif nargs == argparse.ONE_OR_MORE:
                help = 'one or more running domains'
            elif nargs > 1:
                help = '%s running domains' % nargs
            else:
                raise argparse.ArgumentError(
                    nargs, "Passed unexpected value {!s} as {!s} nargs ".format(
                        nargs, dest))
        super(RunningVmNameAction, self).__init__(
            option_strings, dest=dest, help=help, nargs=nargs, **kwargs) 
Example 4
Project: ceph-lcm   Author: Mirantis   File: cliutils.py    (license) View Source Project 5 votes vote down vote up
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() 
Example 5
Project: qubes-core-admin-client   Author: QubesOS   File: __init__.py    (license) View Source Project 5 votes vote down vote up
def __init__(self, want_app=True, want_app_no_instance=False,
                 vmname_nargs=None, **kwargs):

        super(QubesArgumentParser, self).__init__(**kwargs)

        self._want_app = want_app
        self._want_app_no_instance = want_app_no_instance
        self._vmname_nargs = vmname_nargs
        if self._want_app:
            self.add_argument('--qubesxml', metavar='FILE', action='store',
                              dest='app', help=argparse.SUPPRESS)
            self.add_argument('--offline-mode', action='store_true',
                default=None, dest='offline_mode', help=argparse.SUPPRESS)


        self.add_argument('--verbose', '-v', action='count',
                          help='increase verbosity')

        self.add_argument('--quiet', '-q', action='count',
                          help='decrease verbosity')

        self.add_argument('--force-root', action='store_true',
                          default=False, help=argparse.SUPPRESS)

        if self._vmname_nargs in [argparse.ZERO_OR_MORE, argparse.ONE_OR_MORE]:
            vm_name_group = VmNameGroup(self, self._vmname_nargs)
            self._mutually_exclusive_groups.append(vm_name_group)
        elif self._vmname_nargs is not None:
            self.add_argument('VMNAME', nargs=self._vmname_nargs,
                              action=VmNameAction)

        self.set_defaults(verbose=1, quiet=0) 
Example 6
Project: ceph-lcm   Author: Mirantis   File: ceph_verify.py    (license) View Source Project 4 votes vote down vote up
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()