"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@oclif/core");
const nest_app_1 = require("../../lib/nest-app");
const cli_observability_cluster_service_1 = require("../../services/cli-observability-cluster.service");
const cli_ssh_service_1 = require("../../services/cli-ssh.service");
class EnvKubectl extends core_1.Command {
    async run() {
        const { argv } = await this.parse(EnvKubectl);
        const cmd = argv.join(' ');
        const app = await (0, nest_app_1.getNestApp)();
        try {
            const obs = app.get(cli_observability_cluster_service_1.CliObservabilityClusterService);
            const ssh = app.get(cli_ssh_service_1.CliSshService);
            const cluster = await obs.getObservabilityCluster();
            if (!cluster?.masterIpAddress)
                throw new Error('no master ip');
            try {
                process.stdout.write((await ssh.sshExec(cluster.masterIpAddress, cmd)) + '\n');
            }
            catch (e) {
                process.stderr.write(`ERR: ${e.message}\n`);
            }
        }
        finally {
            await (0, nest_app_1.closeNestApp)();
        }
    }
}
EnvKubectl.description = 'Run a remote command on the master via SSH+cert';
EnvKubectl.args = { cmd: core_1.Args.string({ required: true }) };
EnvKubectl.strict = false;
exports.default = EnvKubectl;
