def get_arg_parser()

in sagemaker_image_builder/main.py [0:0]


def get_arg_parser():
    parser = argparse.ArgumentParser(description="A command line utility to create new image versions.")

    subparsers = parser.add_subparsers(dest="subcommand")

    create_major_version_parser = subparsers.add_parser(
        "create-major-version-artifacts", help="Creates a new image major version."
    )
    create_major_version_parser.set_defaults(func=create_major_version_artifacts, runtime_version_upgrade_type=_MAJOR)

    create_minor_version_parser = subparsers.add_parser(
        "create-minor-version-artifacts", help="Creates a new image minor version."
    )
    create_minor_version_parser.set_defaults(func=create_minor_version_artifacts, runtime_version_upgrade_type=_MINOR)

    create_patch_version_parser = subparsers.add_parser(
        "create-patch-version-artifacts", help="Creates a new image patch version."
    )
    create_patch_version_parser.set_defaults(func=create_patch_version_artifacts, runtime_version_upgrade_type=_PATCH)

    # Common arguments
    for p in [create_major_version_parser, create_minor_version_parser, create_patch_version_parser]:
        p.add_argument(
            "--base-patch-version",
            required=True,
            help="Specify the base patch version from which a new version should be created.",
        )
        p.add_argument(
            "--image-config-file",
            required=True,
            help="A json file contains the docker image generator configuration.",
        )
        p.add_argument(
            "--pre-release-identifier",
            help="Optionally specify the pre-release identifier for this new version that should be created.",
        )
        p.add_argument(
            "--force",
            action="store_true",
            help="Overwrites any existing directory corresponding to the new version that will be generated.",
        )

    build_image_parser = subparsers.add_parser("build", help="Builds a new image from the Dockerfile.")
    build_image_parser.add_argument(
        "--target-patch-version",
        required=True,
        help="Specify the target version of image needs to be built.",
    )
    build_image_parser.add_argument(
        "--image-config-file",
        required=True,
        help="A json file containing the docker image generator configuration.",
    )
    build_image_parser.add_argument(
        "--force",
        action="store_true",
        help="Builds a new docker image which will fetch the latest versions of each package in "
        "the conda environment. Any existing env.out file will be overwritten.",
    )
    build_image_parser.add_argument(
        "--target-ecr-repo",
        action="append",
        help="Specify the AWS ECR repository in which this image needs to be uploaded.",
    )
    build_image_parser.add_argument("--region", help="Specify the region of the ECR repository.")
    build_image_parser.set_defaults(func=build_images)

    package_staleness_parser = subparsers.add_parser(
        "generate-staleness-report",
        help="Generates package staleness report for each of the marquee packages in the given image version.",
    )
    package_staleness_parser.set_defaults(func=generate_package_staleness_report)
    package_staleness_parser.add_argument(
        "--image-config-file",
        required=True,
        help="A json file contains the docker image generator configuration.",
    )
    package_staleness_parser.add_argument(
        "--target-patch-version",
        required=True,
        help="Specify the base patch version for which the package staleness report needs to be generated.",
    )

    package_size_parser = subparsers.add_parser(
        "generate-size-report",
        help="Generates package size report for each of the packages in the given image version.",
    )
    package_size_parser.set_defaults(func=generate_package_size_report)
    package_size_parser.add_argument(
        "--image-config-file",
        required=True,
        help="A json file contains the docker image generator configuration.",
    )
    package_size_parser.add_argument(
        "--base-patch-version",
        required=False,
        help="Specify the base patch version for which the package size report needs to be generated.",
    )
    package_size_parser.add_argument(
        "--target-patch-version",
        required=True,
        help="Specify the target patch version for which the package size report needs to be generated.",
    )
    package_size_parser.add_argument(
        "--validate",
        action="store_true",
        help="Validate package size delta and raise error if the validation failed.",
    )

    conda_package_metadata_parser = subparsers.add_parser(
        "get-conda-package-metadata",
        help="Collect and dump conda package versions and sizes in current activated conda environment.",
    )
    conda_package_metadata_parser.set_defaults(func=dump_conda_package_metadata)
    conda_package_metadata_parser.add_argument(
        "-H", "--human-readable", action="store_true", help="Print human-readable size information"
    )
    return parser