// SPDX-License-Identifier: Apache-2.0
import { Flags as flags } from '../../src/commands/flags.js';
import { getTestCacheDirectory, getTestCluster } from '../test-utility.js';
import { K8Client } from '../../src/integration/kube/k8-client/k8-client.js';
import * as helpers from '../../src/core/helpers.js';
export class Argv {
    args = {};
    cacheDir;
    deployment;
    command;
    subcommand;
    constructor() { }
    setArg(flag, value) {
        this.args[flag.name] = value;
    }
    getArg(flag) {
        return this.args[flag.name];
    }
    setCommand(command, subcommand) {
        this.command = command;
        this.subcommand = subcommand;
    }
    build() {
        if (this.getArg(flags.nodeAliasesUnparsed)?.split(',')?.length) {
            const nodeAliases = helpers.parseNodeAliases(this.getArg(flags.nodeAliasesUnparsed));
            this.setArg(flags.numberOfConsensusNodes, nodeAliases.length);
        }
        const rawArguments = structuredClone(this.args);
        const _ = [this.command];
        if (this.subcommand) {
            if (this.subcommand.includes(' ')) {
                _.push(...this.subcommand.split(' '));
            }
            else {
                _.push(this.subcommand);
            }
        }
        rawArguments._ = _;
        return rawArguments;
    }
    clone() {
        const cloned = new Argv();
        cloned.args = structuredClone(this.args);
        cloned.cacheDir = this.cacheDir;
        cloned.deployment = this.deployment;
        return cloned;
    }
    static initializeEmpty() {
        return new Argv();
    }
    /** Get argv with defaults */
    static getDefaultArgv(namespace) {
        const argv = new Argv();
        for (const f of flags.allFlags) {
            argv.setArg(f, f.definition.defaultValue);
        }
        const currentDeployment = argv.getArg(flags.deployment) ||
            `${namespace?.name || argv.getArg(flags.namespace)}-deployment`;
        const cacheDirectory = getTestCacheDirectory();
        argv.cacheDir = cacheDirectory;
        argv.setArg(flags.cacheDir, cacheDirectory);
        argv.deployment = currentDeployment;
        argv.setArg(flags.deployment, currentDeployment);
        argv.setArg(flags.clusterRef, getTestCluster());
        argv.setArg(flags.deploymentClusters, [getTestCluster()]);
        argv.setArg(flags.context, new K8Client(undefined).contexts().readCurrent());
        argv.setArg(flags.chartDirectory, process.env.SOLO_CHARTS_DIR ?? undefined);
        argv.setArg(flags.quiet, true);
        return argv;
    }
}
//# sourceMappingURL=argv-wrapper.js.map