UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

133 lines • 5.41 kB
"use strict"; /** * Config Set Command - Set configuration values */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configSet = exports.ConfigSetCommand = void 0; const fs = __importStar(require("fs-extra")); const chalk_1 = __importDefault(require("chalk")); const ora_1 = __importDefault(require("ora")); const ajv_1 = __importDefault(require("ajv")); const schema_1 = require("./schema"); class ConfigSetCommand { static async execute(options) { const spinner = (0, ora_1.default)('Setting configuration value...').start(); try { // Validate inputs if (!options.key || options.key.trim() === '') { throw new Error('Invalid key: key cannot be empty'); } // Determine config file path const configPath = options.config || this.DEFAULT_CONFIG_PATH; // Check if config exists if (!(await fs.pathExists(configPath))) { throw new Error(`Configuration file not found: ${configPath}`); } // Read current configuration const config = await fs.readJson(configPath); // Parse and set the value const parsedValue = this.parseValue(options.value); this.setNestedValue(config, options.key, parsedValue); // Validate updated configuration const ajv = new ajv_1.default({ allErrors: true, strictTypes: false }); const validate = ajv.compile(schema_1.AQEConfigSchema); const valid = validate(config); if (!valid) { const errors = validate.errors ?.map((err) => `${err.instancePath}: ${err.message}`) .join(', '); throw new Error(`Configuration validation failed after setting value: ${errors}`); } // Write updated configuration await fs.writeJson(configPath, config, { spaces: 2 }); spinner.succeed(chalk_1.default.green('Configuration value set successfully!')); console.log(chalk_1.default.blue('\nšŸ“ Updated Configuration:')); console.log(chalk_1.default.gray(` Key: ${options.key}`)); console.log(chalk_1.default.gray(` Value: ${JSON.stringify(parsedValue, null, 2)}`)); console.log(chalk_1.default.yellow('\nšŸ’” Tip:')); console.log(chalk_1.default.gray(' Verify the change: aqe config get --key ' + options.key)); } catch (error) { spinner.fail(chalk_1.default.red('Failed to set configuration value')); throw error; } } static parseValue(value) { // Try to parse as JSON first try { return JSON.parse(value); } catch { // Not JSON, continue with other parsers } // Try to parse as number if (/^-?\d+(\.\d+)?$/.test(value)) { const num = Number(value); if (!isNaN(num)) { return num; } } // Try to parse as boolean if (value.toLowerCase() === 'true') return true; if (value.toLowerCase() === 'false') return false; // Try to parse as array (comma-separated) if (value.includes(',')) { return value.split(',').map((v) => v.trim()); } // Return as string return value; } static setNestedValue(obj, path, value) { const keys = path.split('.'); let current = obj; // Navigate to the parent object for (let i = 0; i < keys.length - 1; i++) { const key = keys[i]; if (!(key in current)) { current[key] = {}; } current = current[key]; } // Set the final value const finalKey = keys[keys.length - 1]; current[finalKey] = value; } } exports.ConfigSetCommand = ConfigSetCommand; ConfigSetCommand.DEFAULT_CONFIG_PATH = '.agentic-qe/config/aqe.config.json'; /** * Wrapper function for CLI usage */ async function configSet(options) { return ConfigSetCommand.execute(options); } exports.configSet = configSet; //# sourceMappingURL=set.js.map