diff --git a/client.js b/client.js index 443e32c..f61ba5d 100644 --- a/client.js +++ b/client.js @@ -420,4 +420,56 @@ program console.log(`${type} config saved successfully to: ${configFilePath}`); }); +// config +program + .command("config-get") + .description("get type from config file") + .addArgument( + new Argument("", "config type").choices([ + "access", + "token", + "server", + "client", + "key", + ]) + ) + .option("-p --profile ", "setting profile name", PROFILE_DEFAULT) + .action(async (type, options) => { + if (!type) { + console.error("type config is required!"); + return; + } + + const configDir = path.resolve(os.homedir(), PROFILE_PATH); + if (!fs.existsSync(configDir)) { + console.log(`config file ${configDir} not found`); + return; + } + + let config = {}; + const configFilename = `${options.profile}.json`; + const configFilePath = path.resolve(configDir, configFilename); + + if (fs.existsSync(configFilePath)) { + config = JSON.parse(fs.readFileSync(configFilePath, "utf8")); + } else { + console.log(`config file ${configFilePath} not found`); + return; + } + + if (type === "token" || type === "jwt") { + console.log(`token: ${config.token}`); + } else if (type === "server") { + console.log(`server: ${config.server}`); + } else if (type === "clientId" || type === "client") { + console.log(`client: ${config.clientId}`); + } else if (type === "apiKey" || type === "key") { + console.log(`key: ${config.apiKey}`); + } else if (type === "access") { + console.log(`access: ${config.access}`); + } else { + console.log('no config found for type: "' + type + '"'); + } + }); + program.parse(); diff --git a/package.json b/package.json index 90d0806..bb89590 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cubetiq/hlt", - "version": "0.0.2", + "version": "0.0.3", "description": "A lightweight http tunnel client using nodejs and socket.io client", "main": "client.js", "bin": {