def create_parser()

in mozregression/cli.py [0:0]


def create_parser(defaults):
    """
    Create the mozregression command line parser (ArgumentParser instance).
    """
    usage = (
        "\n"
        " %(prog)s [OPTIONS]"
        " [--bad DATE|BUILDID|RELEASE|CHANGESET]"
        " [--good DATE|BUILDID|RELEASE|CHANGESET]"
        "\n"
        " %(prog)s [OPTIONS] --launch DATE|BUILDID|RELEASE|CHANGESET"
        "\n"
        " %(prog)s --list-build-types"
        "\n"
        " %(prog)s --list-releases"
        "\n"
        " %(prog)s --write-conf"
    )

    parser = ArgumentParser(usage=usage)
    parser.add_argument(
        "--version",
        action="version",
        version=__version__,
        help=("print the mozregression version number and" " exits."),
    )

    parser.add_argument(
        "-b",
        "--bad",
        metavar="DATE|BUILDID|RELEASE|CHANGESET",
        help=(
            "first known bad build, default is today."
            " It can be a date (YYYY-MM-DD), a build id,"
            " a release number or a changeset."
        ),
    )

    parser.add_argument(
        "-g",
        "--good",
        metavar="DATE|BUILDID|RELEASE|CHANGESET",
        help=("last known good build. Same possible values" " as the --bad option."),
    )

    parser.add_argument(
        "--list-releases",
        action=ListReleasesAction,
        help="list all known releases and exit",
    )

    parser.add_argument(
        "-B",
        "--build-type",
        default=defaults["build-type"],
        help=(
            "Build type to use, e.g. opt, debug. "
            "See --list-build-types for available values. "
            "Defaults to shippable for desktop Fx, opt for "
            "everything else."
        ),
    )

    parser.add_argument(
        "--list-build-types",
        action=ListBuildTypesAction,
        help="List available build types combinations.",
    )

    parser.add_argument(
        "--find-fix",
        action="store_true",
        help="Search for a bug fix instead of a regression.",
    )

    parser.add_argument(
        "-e",
        "--addon",
        dest="addons",
        action="append",
        default=[],
        metavar="PATH1",
        help="addon to install; repeat for multiple addons.",
    )

    parser.add_argument(
        "-p",
        "--profile",
        default=defaults["profile"],
        metavar="PATH",
        help="profile to use with nightlies.",
    )

    parser.add_argument(
        "--adb-profile-dir",
        dest="adb_profile_dir",
        default=defaults["adb-profile-dir"],
        help=(
            "Path to use on android devices for storing"
            " the profile. Generally you should not need"
            " to specify this, and an appropriate path"
            " will be used. Specifying this to a value,"
            " e.g. '/sdcard/tests' will forcibly try to create"
            " the profile inside that folder."
        ),
    )

    parser.add_argument(
        "--profile-persistence",
        choices=("clone", "clone-first", "reuse"),
        default=defaults["profile-persistence"],
        help=(
            "Persistence of the used profile. Before"
            " each tested build, a profile is used. If"
            " the value of this option is 'clone', each"
            " test uses a fresh clone. If the value is"
            " 'clone-first', the profile is cloned once"
            " then reused for all builds during the "
            " bisection. If the value is 'reuse', the given"
            " profile is directly used. Note that the"
            " profile might be modified by mozregression."
            " Defaults to %(default)s."
        ),
    )

    parser.add_argument(
        "-a",
        "--arg",
        dest="cmdargs",
        action="append",
        default=[],
        metavar="ARG1",
        help=(
            "a command-line argument to pass to the"
            " application; repeat for multiple arguments."
            " Use --arg='-option' to pass in options"
            " starting with `-`."
        ),
    )

    parser.add_argument(
        "--pref",
        nargs="*",
        dest="prefs",
        help=(
            " A preference to set. Must be a key-value pair"
            " separated by a ':'. Note that if your"
            " preference is of type float, you should"
            " pass it as a string, e.g.:"
            " --pref \"layers.low-precision-opacity:'0.0'\""
        ),
    )

    parser.add_argument(
        "--preferences",
        nargs="*",
        dest="prefs_files",
        help=(
            "read preferences from a JSON or INI file. For"
            " INI, use 'file.ini:section' to specify a"
            " particular section."
        ),
    )

    parser.add_argument(
        "-n",
        "--app",
        choices=FC_REGISTRY.names(),
        default=defaults["app"],
        help="application name. Default: %(default)s.",
    )

    parser.add_argument(
        "--lang",
        metavar="[ar|es-ES|he|ja|zh-CN|...]",
        help=("build language. Only valid when app is firefox-l10n or thunderbird-l10n."),
    )

    parser.add_argument(
        "--repo",
        metavar="[autoland|mozilla-beta...]",
        default=defaults["repo"],
        help="repository name used for the bisection.",
    )

    parser.add_argument(
        "--bits",
        choices=("32", "64"),
        default=defaults["bits"],
        help=(
            "force 32 or 64 bit version (only applies to"
            " x86_64 boxes). Default: %s bits." % defaults["bits"]
            or mozinfo.bits
        ),
    )

    parser.add_argument(
        "--arch",
        choices=(
            "aarch64",
            "arm",
            "arm64-v8a",
            "armeabi-v7a",
            "x86",
            "x86_64",
        ),
        default=None,
        help=("Force alternate build (applies to Firefox, Firefox-l10n, GVE, Fenix, and Focus)."),
    )

    parser.add_argument(
        "-c",
        "--command",
        help=(
            "Test command to evaluate builds automatically."
            " A return code of 0 will evaluate the build as"
            " good, and any other value as bad."
            " Variables like {binary} can be used, which"
            " will be replaced with their value as retrieved"
            " by the actual build."
        ),
    )

    parser.add_argument(
        "--persist",
        default=defaults["persist"],
        help=(
            "the directory in which downloaded files are" " to persist. Defaults to %(default)r."
        ),
    )

    parser.add_argument(
        "--persist-size-limit",
        type=float,
        default=defaults["persist-size-limit"],
        help=(
            "Size limit for the persist directory in"
            " gigabytes (GiB). When the limit is reached,"
            " old builds are removed. 0 means no limit. Note"
            " that at least 5 build files are kept,"
            " regardless of this value."
            " Defaults to %(default)s."
        ),
    )

    parser.add_argument(
        "--http-timeout",
        type=float,
        default=float(defaults["http-timeout"]),
        help=(
            "Timeout in seconds to abort requests when there"
            " is no activity from the server. Default to"
            " %(default)s seconds - increase this if you"
            " are under a really slow network."
        ),
    )

    parser.add_argument(
        "--no-background-dl",
        action="store_false",
        dest="background_dl",
        default=(defaults["no-background-dl"].lower() not in ("1", "yes", "true")),
        help=(
            "Do not download next builds in the background" " while evaluating the current build."
        ),
    )

    parser.add_argument(
        "--background-dl-policy",
        choices=("cancel", "keep"),
        default=defaults["background-dl-policy"],
        help=(
            "Policy to use for background downloads."
            ' Possible values are "cancel" to cancel all'
            ' pending background downloads or "keep" to keep'
            " downloading them when persist mode is enabled."
            " The default is %(default)s."
        ),
    )

    parser.add_argument(
        "--approx-policy",
        choices=("auto", "none"),
        default=defaults["approx-policy"],
        help=(
            "Policy to reuse approximate persistent builds"
            " instead of downloading the accurate ones."
            " When auto, mozregression will try its best to"
            " reuse the files, meaning that for 7 days of"
            " bisection range it will try to reuse a build"
            " which date approximates the build to download"
            " by one day (before or after). Use none to"
            " disable this behavior."
            " Defaults to %(default)s."
        ),
    )

    parser.add_argument(
        "--launch",
        metavar="DATE|BUILDID|RELEASE|CHANGESET",
        help=("Launch only one specific build. Same possible" " values as the --bad option."),
    )

    parser.add_argument(
        "-P",
        "--process-output",
        choices=("none", "stdout"),
        default=defaults["process-output"],
        help=(
            "Manage process output logging. Set to stdout by"
            " default when the build type is not 'opt'."
        ),
    )

    parser.add_argument(
        "-M",
        "--mode",
        choices=("classic", "no-first-check"),
        default=defaults["mode"],
        help=(
            "bisection mode. 'classic' will check for the"
            " first good and bad builds to really be good"
            " and bad, and 'no-first-check' won't. Defaults"
            " to %(default)s."
        ),
    )

    parser.add_argument(
        "--archive-base-url",
        default=defaults["archive-base-url"],
        help=("Base url used to find the archived builds." " Defaults to %(default)s"),
    )

    parser.add_argument(
        "--write-config",
        action=WriteConfigAction,
        help="Helps to write the configuration file.",
    )

    parser.add_argument("--debug", "-d", action="store_true", help="Show the debug output.")

    return parser