From b4610d83e4ef4ddeec8f6e7dc0159ca84ad97e03 Mon Sep 17 00:00:00 2001 From: gvensan <4477169+gvensan@users.noreply.github.com> Date: Fri, 11 Oct 2024 08:08:42 +0530 Subject: [PATCH] Support for config file specification in any directory as specified in the config parameter value (over and above the default ~/.stm location) --- package.json | 2 +- src/utils/config.ts | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8e1486e..5864a21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@solace-community/stm", - "version": "0.0.59", + "version": "0.0.60", "description": "Solace Try-Me Command Line Tool", "repository": { "type": "git", diff --git a/src/utils/config.ts b/src/utils/config.ts index 3caeb2c..7a0b2f2 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -268,12 +268,18 @@ export const saveConfig = (data: any) => { export const loadConfig = (configFile: string) => { try { + const localFilePath = processPath(`${configFile}`) const filePath = processPath(`${defaultStmHome}/${configFile}`) if (fileExists(filePath)) { Logger.info(`loading configuration '${configFile}'`) const config = readFile(filePath) // TODO: validateConfig(config) return config; + } else if (fileExists(localFilePath)) { + Logger.info(`loading configuration '${configFile}'`) + const config = readFile(filePath) + // TODO: validateConfig(config) + return config; } else { Logger.logDetailedError(`configuration not found`, `${decoratePath(configFile)}`) Logger.logError('exiting...') @@ -322,8 +328,10 @@ export const loadCommandFromConfig = (cmd: string, options: MessageClientOptions var commandName = options.name ? options.name : cmd const filePath = processPath(`${defaultStmHome}/${options.config as string}`) + const localFilePath = processPath(`${options.config as string}`) + var config = null; if (fileExists(filePath)) { - const config = readFile(filePath) + config = readFile(filePath) Logger.info(`loading '${commandName}' command from configuration '${chalk.cyanBright(filePath)}'`) if (!config[group][commandName]) { Logger.logError(`could not find '${commandName}' command`) @@ -349,6 +357,34 @@ export const loadCommandFromConfig = (cmd: string, options: MessageClientOptions configOptions[clientKeys[i]] = config[group][commandName][clientKeys[i]]; } + return configOptions + } else if (fileExists(localFilePath)) { + config = readFile(localFilePath) + Logger.info(`loading '${commandName}' command from configuration '${chalk.cyanBright(localFilePath)}'`) + if (!config[group][commandName]) { + Logger.logError(`could not find '${commandName}' command`) + // commandName = cmd + Logger.logError('exiting...') + process.exit(1) + } + if (config[group][commandName].command !== cmd) { + Logger.logDetailedError(`expected '${commandName}' command, but found '${config[group][commandName].command}'`, `specify a valid command name`) + Logger.logError('exiting...') + process.exit(1) + } + // TODO: validateConfig(config) + + const configOptions:any = {} + const connectionKeys = Object.keys(group === 'manage' ? defaultManageConnectionConfig : defaultMessageConnectionConfig); + for (var i=0; i