UNPKG

@hashgraph/solo

Version:

An opinionated CLI tool to deploy and manage private Hedera Networks.

73 lines 2.71 kB
// SPDX-License-Identifier: Apache-2.0 import { Flags as flags } from '../../src/commands/flags.js'; import * as helpers from '../../src/core/helpers.js'; import { getTestCacheDirectory, getTestCluster } from '../test-utility.js'; import { InjectTokens } from '../../src/core/dependency-injection/inject-tokens.js'; import { container } from 'tsyringe-neo'; export class Argv { args = {}; cacheDir; deployment; command; subcommand; action; constructor() { } setArg(flag, value) { this.args[flag.name] = value; } getArg(flag) { return this.args[flag.name]; } setCommand(command, subcommand, action) { this.command = command; this.subcommand = subcommand; this.action = action; } 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) { _.push(this.subcommand); } if (this.action) { _.push(this.action); } 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, testName) { 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(testName); 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()]); const k8Factory = container.resolve(InjectTokens.K8Factory); argv.setArg(flags.context, k8Factory.default().contexts().readCurrent()); argv.setArg(flags.chartDirectory, process.env.SOLO_CHARTS_DIR ?? undefined); argv.setArg(flags.quiet, true); return argv; } } //# sourceMappingURL=argv-wrapper.js.map