import { captureEvent } from "../common/analytics/lib.js";
import { authenticate } from "../common/middleware/authentication.js";
import { confirmLinkedConfig } from "../common/middleware/confirm-linked-config.js";
import { confirmProductionDeploy } from "../common/middleware/confirm-production-deploy.js";
import { fetchAccount } from "../common/middleware/get-account-param.js";
import { fetchEnvironment, recordEnvironmentExplicit, } from "../common/middleware/get-environment-param.js";
import { fetchProject } from "../common/middleware/get-project-param.js";
import { configure } from "../common/middleware/user-configuration.js";
import { identify } from "../common/middleware/user-identification.js";
import { deploy } from "../deploy/handler.js";
export default {
    desc: "Deploys current Git branch of the current directory",
    command: "deploy",
    builder: (yargs) => {
        return yargs
            .usage("$0 deploy [options]")
            .option("api-key", {
            type: "string",
            describe: "The API Key from Zuplo",
            envVar: "API_KEY",
            alias: "apikey",
        })
            .option("project", {
            type: "string",
            hidden: true,
            describe: "The project name",
        })
            .option("account", {
            type: "string",
            describe: "The account name",
        })
            .option("dir", {
            type: "string",
            describe: "The directory containing your Zuplo API",
            default: ".",
            normalize: true,
            hidden: true,
        })
            .option("verify-remote", {
            deprecated: true,
            type: "boolean",
            describe: "Verify that this Git repository matches the one configured on Zuplo. Use --no-verify-remote to disable.",
            default: false,
        })
            .option("environment", {
            type: "string",
            describe: "The value to use for environment name, instead of the current branch name",
        })
            .option("self-hosted-endpoint", {
            type: "string",
            describe: "The endpoint of your self-hosted service to deploy to",
        })
            .option("override-repo-url", {
            type: "string",
            describe: "Override the repo url reference",
            default: undefined,
            hidden: true,
        })
            .option("fetch-environments", {
            type: "boolean",
            describe: "Fetch the environments for your project from Zuplo. If this is false, then the environment will automatically be detected from the git branch.",
            default: false,
        })
            .option("mtls-certificates-dir", {
            type: "string",
            describe: "Directory containing mtls certificates to use for the deployment, in the hierarchy that you want them to appear in the runtime. Ex: <cert-name>/tls.crt and <cert-name>/tls.key" +
                "All certificates must be in pem format. Only for use for self-hosted deployments.",
            hidden: true,
        })
            .boolean("verify-remote")
            .example([
            [
                "$0 deploy",
                "Deploy the current Git branch using the branch name as the environment name",
            ],
            [
                "$0 deploy --environment my-env",
                "Override the environment name instead of using the Git branch name",
            ],
            [
                "$0 deploy --account my-account --project my-project --environment my-env",
                "Explicitly specify the account, project, and environment",
            ],
        ])
            .middleware([
            authenticate,
            configure,
            confirmLinkedConfig,
            fetchAccount,
            fetchProject,
            recordEnvironmentExplicit,
            fetchEnvironment,
            confirmProductionDeploy,
            identify,
        ]);
    },
    handler: async (argv) => {
        await captureEvent({ argv, event: "zuplo deploy" });
        await deploy(argv);
    },
};
//# sourceMappingURL=deploy.js.map