@lazycatcloud/lzc-cli 1.3.11 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/box/index.js CHANGED
@@ -1,81 +1,86 @@
1
- import logger from "loglevel"
2
- import shellapi from "../shellapi.js"
3
- import { findSshPublicKey, selectSshPublicKey } from "../utils.js"
1
+ import logger from 'loglevel';
2
+ import shellapi from '../shellapi.js';
3
+ import { findSshPublicKey, selectSshPublicKey } from '../utils.js';
4
+ import { t } from '../i18n/index.js';
4
5
 
5
6
  export function boxCommand(box) {
6
- let subCommands = [
7
- {
8
- command: "switch <boxname>",
9
- desc: "设置默认的盒子",
10
- handler: async ({ boxname }) => {
11
- await shellapi.init()
12
- await shellapi.setDefaultBox(boxname)
13
- }
14
- },
15
- {
16
- command: "default",
17
- desc: "输出当前默认的盒子名",
18
- handler: async () => {
19
- await shellapi.init()
20
- console.log(shellapi.boxname)
21
- }
22
- },
23
- {
24
- command: "list",
25
- desc: "查看盒子列表",
26
- builder: (args) => {
27
- args.option("v", {
28
- alias: "verbose",
29
- describe: "查看详细输出",
30
- type: "boolean"
31
- })
32
- },
33
- handler: async ({ verbose }) => {
34
- await shellapi.init()
35
- const boxes = await shellapi.boxList()
36
- if (boxes.length === 0) {
37
- console.log("没有找到任何盒子,赶紧添加一个吧!")
38
- return
39
- }
40
- if (verbose) {
41
- console.log(JSON.stringify(boxes, undefined, "\t"))
42
- return
43
- }
7
+ let subCommands = [
8
+ {
9
+ command: 'switch <boxname>',
10
+ desc: t('lzc_cli.lib.box.index.switch_cmd_desc', '设置默认的盒子'),
11
+ handler: async ({ boxname }) => {
12
+ await shellapi.init();
13
+ await shellapi.setDefaultBox(boxname);
14
+ },
15
+ },
16
+ {
17
+ command: 'default',
18
+ desc: t('lzc_cli.lib.box.index.default_cmd_desc', '输出当前默认的盒子名'),
19
+ handler: async () => {
20
+ await shellapi.init();
21
+ console.log(shellapi.boxname);
22
+ },
23
+ },
24
+ {
25
+ command: 'list',
26
+ desc: t('lzc_cli.lib.box.index.list_cmd_desc', '查看盒子列表'),
27
+ builder: (args) => {
28
+ args.option('v', {
29
+ alias: 'verbose',
30
+ describe: t('lzc_cli.lib.box.index.list_cmd_verbose_desc', '查看详细输出'),
31
+ type: 'boolean',
32
+ });
33
+ },
34
+ handler: async ({ verbose }) => {
35
+ await shellapi.init();
36
+ const boxes = await shellapi.boxList();
37
+ if (boxes.length === 0) {
38
+ console.log(t('lzc_cli.lib.box.index.list_cmd_box_not_exist_tips', '没有找到任何盒子,赶紧添加一个吧!'));
39
+ return;
40
+ }
41
+ if (verbose) {
42
+ console.log(JSON.stringify(boxes, undefined, '\t'));
43
+ return;
44
+ }
44
45
 
45
- const list = boxes.map((b) => {
46
- return {
47
- 名称: b.box_name,
48
- 状态: b.status,
49
- 登录用户: b.login_user,
50
- 是否管理员: b.is_admin_login ? "" : "",
51
- 是否默认盒子: b.is_default_box ? "" : ""
52
- }
53
- })
54
- console.table(list)
55
- }
56
- },
57
- {
58
- command: "add-public-key",
59
- desc: "添加public-key到开发者工具中",
60
- handler: async () => {
61
- await shellapi.init()
62
- const keys = await findSshPublicKey()
63
- const sshInfo = await selectSshPublicKey(keys)
64
- logger.debug("ssh public key info", sshInfo)
65
- const pk = Buffer.from(sshInfo.content.trimLeft()).toString("base64")
66
- logger.warn(
67
- `请点击下面的连接,或者复制到浏览器中打开,点击申请完成添加
68
- -> https://dev.${shellapi.boxname}.heiyu.space/auth?key=${pk}
69
- `
70
- )
71
- }
72
- }
73
- ]
74
- box.command({
75
- command: "box",
76
- desc: "盒子管理",
77
- builder: (args) => {
78
- args.command(subCommands)
79
- }
80
- })
46
+ const list = boxes.map((b) => {
47
+ const info = {};
48
+ info[`${t('lzc_cli.lib.box.index.list_cmd_table_box_name', '名称')}`] = b.box_name;
49
+ info[`${t('lzc_cli.lib.box.index.list_cmd_table_status', '状态')}`] = b.status;
50
+ info[`${t('lzc_cli.lib.box.index.list_cmd_table_login_user', '登录用户')}`] = b.login_user;
51
+ info[`${t('lzc_cli.lib.box.index.list_cmd_table_is_admin_login', '是否管理员')}`] = b.is_admin_login ? '' : '';
52
+ info[`${t('lzc_cli.lib.box.index.list_cmd_table_is_default_box', '是否默认盒子')}`] = b.is_default_box ? '' : '';
53
+ return info;
54
+ });
55
+ console.table(list);
56
+ },
57
+ },
58
+ {
59
+ command: 'add-public-key',
60
+ desc: t('lzc_cli.lib.box.index.add_public_key_cmd_desc', '添加public-key到开发者工具中'),
61
+ handler: async () => {
62
+ await shellapi.init();
63
+ const keys = await findSshPublicKey();
64
+ const sshInfo = await selectSshPublicKey(keys);
65
+ logger.debug('ssh public key info', sshInfo);
66
+ const pk = Buffer.from(sshInfo.content.trimLeft()).toString('base64');
67
+ logger.warn(
68
+ t(
69
+ 'lzc_cli.lib.box.index.add_public_key_cmd_apply_tips',
70
+ `请点击下面的连接,或者复制到浏览器中打开,点击申请完成添加
71
+ -> https://dev.{{boxname}}.heiyu.space/auth?key={{pk}}
72
+ `,
73
+ { boxname: shellapi.boxname, pk: pk },
74
+ ),
75
+ );
76
+ },
77
+ },
78
+ ];
79
+ box.command({
80
+ command: 'box',
81
+ desc: t('lzc_cli.lib.box.index.box_cmd_desc', '盒子管理'),
82
+ builder: (args) => {
83
+ args.command(subCommands);
84
+ },
85
+ });
81
86
  }
package/lib/config/env.js CHANGED
@@ -4,7 +4,7 @@ import { ensureDir } from "../utils.js"
4
4
  import logger from "loglevel"
5
5
  import os from "node:os"
6
6
 
7
- const _SYSTEM_ENV_PREFIX = "LZC_CLI_"
7
+ export const _SYSTEM_ENV_PREFIX = "LZC_CLI"
8
8
 
9
9
  export const GLOBAL_CONFIG_DIR = path.join(
10
10
  os.homedir(),
@@ -26,7 +26,7 @@ class Env {
26
26
 
27
27
  get(key) {
28
28
  // 优先通过环境变量获取 (支持 CI/CD)
29
- const _env_key = `${_SYSTEM_ENV_PREFIX}${(key ?? "").toUpperCase()}`
29
+ const _env_key = `${_SYSTEM_ENV_PREFIX}_${(key ?? "").toUpperCase()}`
30
30
  if (process.env[_env_key]) {
31
31
  return process.env[_env_key]
32
32
  }
@@ -1,57 +1,61 @@
1
- import env from "./env.js"
2
- import logger from "loglevel"
1
+ import env from './env.js';
2
+ import logger from 'loglevel';
3
+ import { t } from '../i18n/index.js';
3
4
 
4
5
  export function configCommand(program) {
5
- const subCommands = [
6
- {
7
- command: "set [key] [value]",
8
- desc: "设置配置",
9
- handler: async ({ key, value }) => {
10
- if (!key && !value) {
11
- throw `key 和 value 不能为空`
12
- }
13
- const pair = Object.fromEntries([[key, value]])
14
- env.set(pair)
15
- logger.info(`${key} 配置成功!`)
16
- }
17
- },
18
- {
19
- command: "del [key]",
20
- desc: "删除配置",
21
- handler: async ({ key, value }) => {
22
- if (key) {
23
- env.del(key)
24
- logger.info(`删除 ${key} 成功!`)
25
- return
26
- }
27
- }
28
- },
29
- {
30
- command: "get [key]",
31
- desc: "获取配置",
32
- handler: async ({ key }) => {
33
- if (key) {
34
- const v = env.get(key)
35
- logger.info(`${key} ${v}`)
36
- } else {
37
- const all = env.all()
38
- Object.keys(all).forEach((k) => {
39
- logger.info(`${k} ${all[k]}`)
40
- })
41
- }
42
- return
43
- }
44
- }
45
- ]
46
- program.command({
47
- command: "config",
48
- desc: "配置管理",
49
- builder: (args) => {
50
- args.command(subCommands)
51
- args
52
- .example("$0 config get", "列出所有配置")
53
- .example("$0 config get foo", "获取key为foo的配置")
54
- .example("$0 config set noCheckVersion false", "禁用lzc-cli的版本检测")
55
- }
56
- })
6
+ const subCommands = [
7
+ {
8
+ command: 'set [key] [value]',
9
+ desc: t('lzc_cli.lib.config.index.set_cmd_desc', '设置配置'),
10
+ handler: async ({ key, value }) => {
11
+ if (!key && !value) {
12
+ throw t('lzc_cli.lib.config.index.set_cmd_key_or_value_is_empty_fail', `key 和 value 不能为空`);
13
+ }
14
+ const pair = Object.fromEntries([[key, value]]);
15
+ env.set(pair);
16
+ logger.info(
17
+ t('lzc_cli.lib.config.index.set_cmd_success_tips', `{{key}} 配置成功!`, {
18
+ key,
19
+ }),
20
+ );
21
+ },
22
+ },
23
+ {
24
+ command: 'del [key]',
25
+ desc: t('lzc_cli.lib.config.index.del_cmd_desc', '删除配置'),
26
+ handler: async ({ key }) => {
27
+ if (key) {
28
+ env.del(key);
29
+ logger.info(t('lzc_cli.lib.config.index.del_cmd_success', `删除 {{key}} 成功!`, { key }));
30
+ return;
31
+ }
32
+ },
33
+ },
34
+ {
35
+ command: 'get [key]',
36
+ desc: t('lzc_cli.lib.config.index.get_cmd_desc', '获取配置'),
37
+ handler: async ({ key }) => {
38
+ if (key) {
39
+ const v = env.get(key);
40
+ logger.info(`${key} ${v}`);
41
+ } else {
42
+ const all = env.all();
43
+ Object.keys(all).forEach((k) => {
44
+ logger.info(`${k} ${all[k]}`);
45
+ });
46
+ }
47
+ return;
48
+ },
49
+ },
50
+ ];
51
+ program.command({
52
+ command: 'config',
53
+ desc: t('lzc_cli.lib.config.index.config_cmd_desc', '配置管理'),
54
+ builder: (args) => {
55
+ args.command(subCommands);
56
+ args.example('$0 config get', t('lzc_cli.lib.config.index.config_cmd_list_tips', '列出所有配置'))
57
+ .example('$0 config get foo', t('lzc_cli.lib.config.index.config_cmd_item_tips', '获取key为foo的配置'))
58
+ .example('$0 config set noCheckVersion false', t('lzc_cli.lib.config.index.config_cmd_disable_check_version_tips', '禁用 lzc-cli 的版本更新检测'));
59
+ },
60
+ });
57
61
  }