Example #1
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()

    args = parser.parse_args(argv[1:])

    kwargs = dict(args._get_kwargs())
    return Arguments(**kwargs)
Example #2
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument('name',
                        metavar='NAME',
                        help='Name of the new function / alias.')
    parser.add_argument(
        '-a',
        '--alias',
        action='store_true',
        help='Define alias instead of function.',
    )
    parser.add_argument(
        '-m',
        '--marker',
        default='DEFAULT',
        help='Marks the start line. Defaults to %(default)r.',
    )
    parser.add_argument(
        "-F",
        "--bash-file",
        action="append",
        dest='file_list',
        metavar='FILE',
        help=('File to search when determining where to add new alias'
              ' definition. This option can be given multiple times.'),
    )

    args = parser.parse_args(argv[1:])

    kwargs = dict(args._get_kwargs())
    return Arguments(**kwargs)
Example #3
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument(
        'rise_or_set',
        choices=list(RiseOrSet),
        type=RiseOrSet,
        help='Get sunrise or sunset?',
    )

    args = parser.parse_args(argv[1:])
    kwargs = dict(args._get_kwargs())

    return Arguments(**kwargs)
Example #4
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument(
        "principal",
        type=_positive_num(int),
        help="The principal price of the home (in thousands of dollars).",
    )
    parser.add_argument(
        "-I",
        "--annual-interest-rate",
        type=_positive_num(float, max_value=1.0),
        default=0.04,
        help=("The annual interest rate on the mortgage. Defaults to"
              " %(default)s."),
    )
    parser.add_argument(
        "-D",
        "--deposit",
        type=_positive_num(float),
        default=0.2,
        help=(
            "The deposit you plan to make. This can either be a percentage (0"
            " < deposit < 1) or an absolute value. Defaults to %(default)s."),
    )
    parser.add_argument(
        "-E",
        "--extra-payments",
        default="0:0",
        help=(
            "The amount of your total_extra_payment that you are able to pay"
            " each month and the number of months you are willing to make"
            " these extra payments for. These two values (amount and # of"
            " months) should be seperated by a colon. Defaults to %(default)s."
        ),
    )
    parser.add_argument(
        "-L",
        "--loan-months",
        type=_positive_num(int),
        default=360,
        help="The length of the loan (in months). Defaults to %(default)s.",
    )

    args = parser.parse_args(argv[1:])

    kwargs = dict(args._get_kwargs())
    _kwargs_hook(kwargs, parser.error)

    return Arguments(**kwargs)
Example #5
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser(description=__doc__)
    parser.add_argument("magnet", help="The torrent magnet file.")
    parser.add_argument(
        "-w",
        type=Path,
        dest="download_dir",
        default="/media/bryan/zeus/media/Entertainment/Movies",
        help=("The directory that the torrents will be downloaded to."
              " Defaults to %(default)s."),
    )
    parser.add_argument(
        "-D",
        type=int,
        dest="delay",
        default=0,
        help=("Delay starting the script for DELAY seconds."
              " Defaults to %(default)s."),
    )
    parser.add_argument(
        "-t",
        type=float,
        dest="timeout",
        default=0,
        help=("Time (in hours) to attempt to complete download before timing"
              " out. If set to 0, this script will run forever without ever"
              " timing out. Defaults to %(default)s."),
    )
    parser.add_argument(
        "--pudb",
        action='store_true',
        help="Run `pudb.set_trace()` on startup.",
    )
    parser.add_argument(
        "--threading",
        choices=("y", "n"),
        default="y",
        help="Enable multi-threading. Defaults to '%(default)s'.",
    )
    parser.add_argument(
        "--vpn",
        type=str,
        dest="vpn",
        default="nyc",
        help="VPN to connect to. Defaults to '%(default)s'.",
    )

    args = parser.parse_args(argv[1:])
    return Arguments(**dict(args._get_kwargs()))
Example #6
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument("zipcode",
                        nargs="?",
                        default="08060",
                        help="zip code of location")
    parser.add_argument(
        "--weather-cmd",
        default="weather",
        help=("The command used to retrieve the weather report from the"
              " command-line."),
    )
    parser.add_argument(
        "-n",
        "--attempts",
        type=int,
        default=7,
        help=(
            "How many times should we attempt to run this command in the event"
            " of failure/timeout?"),
    )
    parser.add_argument(
        "-t",
        "--timeout",
        type=int,
        default=30,
        help=("How long should we wait (in seconds) for the this command to"
              " complete?"),
    )
    parser.add_argument(
        "--max-delay",
        default=300,
        type=int,
        help="The maximum sleep time between command attempts.",
    )

    args = parser.parse_args(argv[1:])
    kwargs = dict(args._get_kwargs())

    return Arguments(**kwargs)
Example #7
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument(
        "-C",
        "--generate-cache",
        action="store_true",
        help="Re-generate the document cache.",
    )
    parser.add_argument(
        "-q",
        "--quiet",
        dest="quiet",
        action="store_true",
        help=(
            "Do not prompt the user to choose a document. Use with -C to "
            "silently re-generate the document cache."
        ),
    )
    parser.add_argument(
        "-x",
        "--overwrite",
        action="store_true",
        help="Close current Zathura instance before opening new one.",
    )
    parser.add_argument(
        "-R",
        "--refresh",
        action="store_true",
        help="Closes current Zathura instance and reopens same document.",
    )

    args = parser.parse_args(argv[1:])

    kwargs = dict(args._get_kwargs())
    kwargs["generate_cache"] = (
        kwargs["generate_cache"] or not Path(ALL_DOCS_CACHE_FILE).is_file()
    )

    return Arguments(**kwargs)
Example #8
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument(
        "-V",
        "--python-version",
        action="append",
        dest="python_versions",
        metavar="MAJOR.MINOR",
        type=float,
        help=(
            "A valid python version number (e.g. 2.7, 3.6, 3.7, etc....). This"
            " option can be provided more than once."),
    )
    parser.add_argument(
        "-1",
        "--one-at-a-time",
        action="store_true",
        help="Install each Python pacakge individually.",
    )
    parser.add_argument(
        "python_packages",
        metavar="PYPACK",
        nargs="+",
        type=str,
        help="Python packages to install (if not already installed).",
    )

    args = parser.parse_args(argv[1:])

    if args.python_versions is None:
        parser.error(
            "At least one python version number must be provided (using the -v"
            " option).")

    kwargs = dict(args._get_kwargs())
    return Arguments(**kwargs)
Example #9
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()
    parser.add_argument(
        "password_length",
        nargs="?",
        default="12:20",
        help=("The length (in characters) of the password to generate. You can"
              " specify a specific length (e.g. '15') or a lower bound and an"
              " upper bound, separated by a colon, to randomly select the"
              " password length from (e.g. '8:15' will randomly select a"
              " password length between 8 and 15). Defaults to %(default)r."),
    )
    parser.add_argument(
        "-U",
        "--no-uppercase",
        dest="use_uppercase",
        action="store_false",
        help="Do NOT allow uppercase letters to be included in the password.",
    )
    parser.add_argument(
        "-L",
        "--no-lowercase",
        dest="use_lowercase",
        action="store_false",
        help="Do NOT allow lowercase letters to be included in the password.",
    )
    parser.add_argument(
        "-D",
        "--no-digits",
        dest="use_digits",
        action="store_false",
        help="Do NOT allow digits (i.e. 0-9) to be included in the password.",
    )
    parser.add_argument(
        "-S",
        "--no-symbols",
        dest="use_symbols",
        action="store_false",
        help=(
            "Do NOT allow symbols (e.g. '@', '!', '>', ...) to be included in"
            " the password."),
    )
    parser.add_argument(
        "-i",
        "--include-chars",
        help=(
            "Extra characters to consider when randomly generating a password."
        ),
    )
    parser.add_argument(
        "-x",
        "--exclude-chars",
        help=("Characters to explicitly exclude from the characters which are"
              " considered when randomly generating a password."),
    )

    args = parser.parse_args(argv[1:])
    _validate_cli_args(args, parser.error)

    kwargs = dict(args._get_kwargs())
    _set_password_length(kwargs)

    return Arguments(**kwargs)
Example #10
0
def parse_cli_args(argv: Sequence[str]) -> Arguments:
    parser = gutils.ArgumentParser()

    parser.add_argument(
        "-M",
        "--max-days",
        nargs="?",
        help=(
            "Max number of days without update before complaining. This "
            "option is only checked when used with the '--maint-check' option."
        ),
    )

    g1 = parser.add_mutually_exclusive_group()
    g1.add_argument(
        "-u",
        "--update",
        dest="action",
        action="store_const",
        const=Action.UPDATE,
        help="Update the machine.",
    )
    g1.add_argument(
        "-c",
        "--cleanup",
        dest="action",
        action="store_const",
        const=Action.CLEANUP,
        help="Run cleanup tasks.",
    )
    g1.add_argument(
        "-m",
        "--maint-check",
        dest="action",
        action="store_const",
        const=Action.MAINT_CHECK,
        help="Check if any maintenance is due.",
    )

    g2 = parser.add_mutually_exclusive_group()
    g2.add_argument(
        "-D",
        "--days-since-last",
        dest="dsl",
        choices=["local", "remote"],
        help=(
            'Prints the number of days its been since the specified '
            'maintenance task was last performed. This option takes an '
            'argument indicating what machine(s) to check. "local" indicates '
            'the local machine and "remote" indicates all remote machines.'),
    )
    g2.add_argument(
        "-P",
        "--pretend",
        dest="pretend",
        action="store_true",
        help="Prints the command list instead of executing it.",
    )

    args = parser.parse_args(argv[1:])
    kwargs = dict(args._get_kwargs())

    if args.action is None:
        parser.error("Exactly one of the following options MUST be specified:"
                     " [-u | -c | -m]")

    if args.action == Action.MAINT_CHECK and args.max_days is None:
        parser.error(
            "The -M|--max-days option MUST be provided when -m|--maint-check"
            " is specified.")

    return Arguments(**kwargs)