Add list profiles
This commit is contained in:
parent
7d17ee38a4
commit
d5f4abeeb0
@ -1,4 +1,8 @@
|
|||||||
### 14/07/2023 (1.0.8)
|
### 27/07/2023 (1.0.10)
|
||||||
|
|
||||||
|
- Add list profiles
|
||||||
|
|
||||||
|
### 14/07/2023 (1.0.9)
|
||||||
|
|
||||||
- Fixed the start with port unable to start
|
- Fixed the start with port unable to start
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@cubetiq/hlt",
|
"name": "@cubetiq/hlt",
|
||||||
"version": "0.1.9",
|
"version": "0.1.10",
|
||||||
"description": "A lightweight http tunnel client using nodejs and socket.io client",
|
"description": "A lightweight http tunnel client using nodejs and socket.io client",
|
||||||
"main": "dist/cli.js",
|
"main": "dist/cli.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
34
src/cli.ts
34
src/cli.ts
@ -4,6 +4,7 @@ import * as os from "os";
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { initConfigFileClient, startClient } from "./api";
|
import { initConfigFileClient, startClient } from "./api";
|
||||||
import { PROFILE_DEFAULT, PROFILE_PATH, SERVER_DEFAULT_URL, TOKEN_FREE } from "./constant";
|
import { PROFILE_DEFAULT, PROFILE_PATH, SERVER_DEFAULT_URL, TOKEN_FREE } from "./constant";
|
||||||
|
import { listProfile } from "./manage";
|
||||||
import { createProxyServer } from "./proxy";
|
import { createProxyServer } from "./proxy";
|
||||||
import { createProxyServer as createProxyTCPServer } from "./proxy_tcp";
|
import { createProxyServer as createProxyTCPServer } from "./proxy_tcp";
|
||||||
import { getTokenFree } from './sdk';
|
import { getTokenFree } from './sdk';
|
||||||
@ -22,20 +23,20 @@ program
|
|||||||
program
|
program
|
||||||
.command("init")
|
.command("init")
|
||||||
.description("generate a new client and token with free access")
|
.description("generate a new client and token with free access")
|
||||||
.option("-s --server <string>", "setting server url", SERVER_DEFAULT_URL)
|
.option("-s, --server <string>", "setting server url", SERVER_DEFAULT_URL)
|
||||||
.option(
|
.option(
|
||||||
"-t --token <string>",
|
"-t, --token <string>",
|
||||||
"setting token (default generate FREE access token)",
|
"setting token (default generate FREE access token)",
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
.option("-a --access <string>", "setting token access type", TOKEN_FREE)
|
.option("-a, --access <string>", "setting token access type", TOKEN_FREE)
|
||||||
.option("-c --client <string>", "setting client (auto generate uuid)")
|
.option("-c, --client <string>", "setting client (auto generate uuid)")
|
||||||
.option(
|
.option(
|
||||||
"-k --key <string>",
|
"-k, --key <string>",
|
||||||
"setting client api key for authentication access"
|
"setting client api key for authentication access"
|
||||||
)
|
)
|
||||||
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
||||||
.option("-f --force", "force to generate new client and token", false)
|
.option("-f, --force", "force to generate new client and token", false)
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
initConfigFileClient(options);
|
initConfigFileClient(options);
|
||||||
});
|
});
|
||||||
@ -91,7 +92,7 @@ program
|
|||||||
])
|
])
|
||||||
)
|
)
|
||||||
.argument("<value>", "config value")
|
.argument("<value>", "config value")
|
||||||
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
||||||
.action(async (type, value, options) => {
|
.action(async (type, value, options) => {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
console.error("type config is required!");
|
console.error("type config is required!");
|
||||||
@ -179,7 +180,7 @@ program
|
|||||||
"key",
|
"key",
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
.option("-p --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
.option("-p, --profile <string>", "setting profile name", PROFILE_DEFAULT)
|
||||||
.action(async (type, options) => {
|
.action(async (type, options) => {
|
||||||
if (!type) {
|
if (!type) {
|
||||||
console.error("type config is required!");
|
console.error("type config is required!");
|
||||||
@ -271,7 +272,7 @@ program
|
|||||||
|
|
||||||
throw new InvalidArgumentError("Target is not a url or host with port.");
|
throw new InvalidArgumentError("Target is not a url or host with port.");
|
||||||
})
|
})
|
||||||
.option("-p --profile <string>", "setting profile name for connect with hlt server (proxy with current local port)")
|
.option("-p, --profile <string>", "setting profile name for connect with hlt server (proxy with current local port)")
|
||||||
.action((port, target, options) => {
|
.action((port, target, options) => {
|
||||||
const isTcp = target.indexOf("tcp") === 0;
|
const isTcp = target.indexOf("tcp") === 0;
|
||||||
if (isTcp) {
|
if (isTcp) {
|
||||||
@ -322,4 +323,17 @@ const onConnectProxy = (port: number, options: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// profile
|
||||||
|
program
|
||||||
|
.command("profile")
|
||||||
|
.description("manage profile")
|
||||||
|
.option("-l, --list", "list all profiles", false)
|
||||||
|
.action((options) => {
|
||||||
|
if (options.list) {
|
||||||
|
listProfile();
|
||||||
|
} else {
|
||||||
|
console.log("profile command is required");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
program.parse();
|
program.parse();
|
||||||
|
28
src/manage.ts
Normal file
28
src/manage.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import * as fs from "fs";
|
||||||
|
import * as os from "os";
|
||||||
|
import * as path from "path";
|
||||||
|
import { PROFILE_DEFAULT, PROFILE_PATH } from "./constant";
|
||||||
|
|
||||||
|
export const listProfile = () => {
|
||||||
|
const configDir = path.resolve(os.homedir(), PROFILE_PATH);
|
||||||
|
if (!fs.existsSync(configDir)) {
|
||||||
|
console.log(`config file ${configDir} not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const configFiles = fs.readdirSync(configDir);
|
||||||
|
if (configFiles.length === 0) {
|
||||||
|
console.log(`config file ${configDir} not found`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("List of profile:");
|
||||||
|
configFiles.forEach((file) => {
|
||||||
|
const configFilePath = path.resolve(configDir, file);
|
||||||
|
const config = JSON.parse(fs.readFileSync(configFilePath, "utf8"));
|
||||||
|
const name = file.replace(".json", "");
|
||||||
|
console.log(`- ${name} (${config.clientId})`);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`\nCurrent profile: ${PROFILE_DEFAULT}`);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user