UNPKG

@adinsure-ops/ops-cli

Version:

Operations CLI for working with AdInsure

61 lines (60 loc) 2.47 kB
import { __awaiter } from "tslib"; import { Args } from '@oclif/core'; import CommandBase from '../../command.base.js'; import chalk from 'chalk'; import fs from 'fs'; import path from 'path'; import OpsConfig from '../../lib/config.js'; class ConfigSet extends CommandBase { run() { const _super = Object.create(null, { run: { get: () => super.run } }); return __awaiter(this, void 0, void 0, function* () { _super.run.call(this); const { args } = yield this.parse(ConfigSet); const configPath = this.security.getConfigPath(); const config = new OpsConfig(configPath); if (args.type === 'endpoint') { if (args.value !== 'azure' && args.value !== 'gitlabru') { this.error(chalk.red('For endpoint, allowed values are "azure" and "gitlabru".')); } } else if (args.type === 'download_folder') { // Resolve the given path const resolvedPath = path.resolve(args.value); // Check if the path exists and is a directory if (!fs.existsSync(resolvedPath)) { this.error(chalk.red(`The specified download folder does not exist: ${resolvedPath}`)); } else if (!fs.statSync(resolvedPath).isDirectory()) { this.error(chalk.red(`The specified path is not a directory: ${resolvedPath}`)); } // Overwrite args.value with the resolved absolute path for consistency args.value = resolvedPath; } config.set(args.type, args.value); config.save(); this.log(chalk.green(`Configuration updated: ${args.type} = ${args.value}`)); }); } } ConfigSet.aliases = ['config:set']; ConfigSet.description = 'Set a configuration value'; ConfigSet.examples = [ '$ ops config:set endpoint gitlabru', '$ ops config:set endpoint azure', '$ ops config:set download_folder ~/Downloads', ]; ConfigSet.args = { type: Args.string({ description: 'Type of OPS configuration', options: ['endpoint', 'download_folder'], required: true, }), value: Args.string({ description: 'For "endpoint", allowed values: azure, gitlabru; for "download_folder", a valid folder path is expected.', required: true, }) }; export default ConfigSet;