@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
45 lines • 1.97 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { Flags as flags } from '../commands/flags.js';
import { NamespaceName } from '../types/namespace/namespace-name.js';
import { input as inputPrompt } from '@inquirer/prompts';
import { SoloError } from './errors/solo-error.js';
export async function resolveNamespaceFromDeployment(localConfig, configManager, task) {
const deploymentName = await promptTheUserForDeployment(configManager, task);
try {
return NamespaceName.of(localConfig.configuration.deploymentByName(deploymentName).namespace);
}
catch {
const namespaceFromFlag = configManager.getFlag(flags.namespace);
if (namespaceFromFlag) {
return typeof namespaceFromFlag === 'string' ? NamespaceName.of(namespaceFromFlag) : namespaceFromFlag;
}
throw new SoloError(`Deployment ${deploymentName} not found in local config and no --namespace provided`);
}
}
export async function promptTheUserForDeployment(configManager, task) {
if (configManager.getFlag(flags.deployment)) {
return configManager.getFlag(flags.deployment);
}
if (task) {
await configManager.executePrompt(task, [flags.deployment]);
}
else {
const isQuiet = configManager.getFlag(flags.quiet);
const isForced = configManager.getFlag(flags.force);
// if the quiet or forced flag is passed don't prompt the user
if (isQuiet === true || isForced === true) {
throw new SoloError('deployment is required');
}
const answer = await inputPrompt({
message: 'Enter the name of the deployment:',
validate: (value) => !!value,
});
configManager.setFlag(flags.deployment, answer);
}
const deploymentName = configManager.getFlag(flags.deployment);
if (!deploymentName) {
throw new SoloError('deployment is required');
}
return deploymentName;
}
//# sourceMappingURL=resolvers.js.map