Task: Add command for config-get to allow users to fetch the config type and return value back for http tunnel client

This commit is contained in:
Sambo Chea 2022-06-26 14:48:08 +07:00
parent 8e3243f86e
commit cf4b150140
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
2 changed files with 53 additions and 1 deletions

View File

@ -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("<type>", "config type").choices([
"access",
"token",
"server",
"client",
"key",
])
)
.option("-p --profile <string>", "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();

View File

@ -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": {