@univer-cli/config-command 1.0.0-beta.2

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/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @univer-cli/config-command
2
+
3
+ English | [简体中文](./README.zh-CN.md)
4
+
5
+ Add `@univer-cli/config` to a Commander application with a ready-to-use set of local configuration commands.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pnpm add commander @univer-cli/config @univer-cli/config-command
11
+ ```
12
+
13
+ Commander `^15.0.0` is a peer dependency. Requires Node.js 22.12 or higher.
14
+
15
+ ## Quick Start
16
+
17
+ Define the configuration with the capability, then inject it into the command:
18
+
19
+ ```ts
20
+ import { join } from "node:path";
21
+ import { configCodecs, createFileConfig, defineConfig } from "@univer-cli/config";
22
+ import { createConfigCommand } from "@univer-cli/config-command";
23
+ import { Command } from "commander";
24
+
25
+ const config = createFileConfig({
26
+ path: join(process.cwd(), ".my-cli", "config.json"),
27
+ definitions: defineConfig({
28
+ "runtime.enabled": {
29
+ description: "Enable the runtime.",
30
+ defaultValue: true,
31
+ codec: configCodecs.boolean(),
32
+ },
33
+ }),
34
+ });
35
+
36
+ const program = new Command("my-cli");
37
+ program.addCommand(createConfigCommand({ config }));
38
+ await program.parseAsync();
39
+ ```
40
+
41
+ ## Command list
42
+
43
+ ```text
44
+ config path
45
+ config list [--json]
46
+ config get <key> [--json]
47
+ config set <key> <value> [--json]
48
+ config unset <key> [--json]
49
+ ```
50
+
51
+ `set` uses the codec in the configuration definition to parse text, so the CLI and direct capability calls share the same validation. The default output is human-readable; `--json` prints structured results. Commander exits non-zero for unknown keys and invalid values.
52
+
53
+ ## Customization
54
+
55
+ The factory returns a native Commander `Command`. The application can customize its name, aliases, help, output, and exit behavior, or skip the preset and call the capability directly:
56
+
57
+ ```ts
58
+ const entry = await config.get({ key: "runtime.enabled" });
59
+ renderWithMyOwnFormat(entry);
60
+ ```
61
+
62
+ This package does not define configuration keys, default values, or persistence rules; these contracts all belong to `@univer-cli/config`.
@@ -0,0 +1,64 @@
1
+ # @univer-cli/config-command
2
+
3
+ [English](./README.md) | 简体中文
4
+
5
+ 把 `@univer-cli/config` 接入 Commander 应用,提供一组可直接使用的本地配置命令。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ pnpm add commander @univer-cli/config @univer-cli/config-command
11
+ ```
12
+
13
+ Commander `^15.0.0` 是 peer dependency。要求 Node.js 22.12 或更高版本。
14
+
15
+ ## 快速开始
16
+
17
+ 先用 capability 定义配置,再注入 command:
18
+
19
+ ```ts
20
+ import { join } from "node:path";
21
+ import { configCodecs, createFileConfig, defineConfig } from "@univer-cli/config";
22
+ import { createConfigCommand } from "@univer-cli/config-command";
23
+ import { Command } from "commander";
24
+
25
+ const config = createFileConfig({
26
+ path: join(process.cwd(), ".my-cli", "config.json"),
27
+ definitions: defineConfig({
28
+ "runtime.enabled": {
29
+ description: "Enable the runtime.",
30
+ defaultValue: true,
31
+ codec: configCodecs.boolean(),
32
+ },
33
+ }),
34
+ });
35
+
36
+ const program = new Command("my-cli");
37
+ program.addCommand(createConfigCommand({ config }));
38
+ await program.parseAsync();
39
+ ```
40
+
41
+ ## 命令一览
42
+
43
+ ```text
44
+ config path
45
+ config list [--json]
46
+ config get <key> [--json]
47
+ config set <key> <value> [--json]
48
+ config unset <key> [--json]
49
+ ```
50
+
51
+ `set` 使用配置定义中的 codec 解析文本,因此 CLI 与直接调用 capability 共享相同校验。默认输出面向人阅读;
52
+ `--json` 输出结构化结果。未知 key 和非法值由 Commander 以失败退出处理。
53
+
54
+ ## 定制
55
+
56
+ Factory 返回原生 Commander `Command`。Application 可以修改名称、alias、help、输出或退出行为,也可以跳过
57
+ preset,直接调用 capability:
58
+
59
+ ```ts
60
+ const entry = await config.get({ key: "runtime.enabled" });
61
+ renderWithMyOwnFormat(entry);
62
+ ```
63
+
64
+ 本 package 不定义配置 key、默认值或持久化规则;这些合同全部属于 `@univer-cli/config`。
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';module['exports']=require('./index.mjs');
@@ -0,0 +1,9 @@
1
+ import { Config } from "@univer-cli/config";
2
+ import { Command } from "commander";
3
+ //#region src/index.d.ts
4
+ interface ConfigCommandDependencies {
5
+ readonly config: Config;
6
+ }
7
+ declare function createConfigCommand(dependencies: ConfigCommandDependencies): Command;
8
+ //#endregion
9
+ export { ConfigCommandDependencies, createConfigCommand };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ (function(_0x412f2a,_0x4e2b67){const _0xd17f43=_0x331e,_0x146090=_0x412f2a();while(!![]){try{const _0x44a01=parseInt(_0xd17f43(0x20f))/0x1+parseInt(_0xd17f43(0x1fd))/0x2+parseInt(_0xd17f43(0x20b))/0x3*(-parseInt(_0xd17f43(0x200))/0x4)+-parseInt(_0xd17f43(0x206))/0x5+parseInt(_0xd17f43(0x1ff))/0x6*(parseInt(_0xd17f43(0x205))/0x7)+parseInt(_0xd17f43(0x1fc))/0x8+-parseInt(_0xd17f43(0x21c))/0x9*(parseInt(_0xd17f43(0x216))/0xa);if(_0x44a01===_0x4e2b67)break;else _0x146090['push'](_0x146090['shift']());}catch(_0x46c713){_0x146090['push'](_0x146090['shift']());}}}(_0x12a8,0x7b536));import{ConfigError as _0xb974c2}from'@univer-cli/config';import{Command as _0x28bf41}from'commander';function n(_0x4d5565){const _0x1743ba=_0x331e;let _0x94c1dc=new _0x28bf41(_0x1743ba(0x21b))['description'](_0x1743ba(0x1f2))[_0x1743ba(0x218)](()=>_0x94c1dc['outputHelp']());return _0x94c1dc[_0x1743ba(0x21a)](_0x1743ba(0x209))[_0x1743ba(0x1fe)]('Show\x20the\x20config\x20file\x20path')[_0x1743ba(0x204)](_0x1743ba(0x203),_0x1743ba(0x208))['action'](_0x5f4181=>{const _0x228f3c=_0x1743ba;a(_0x94c1dc,_0x5f4181,{'path':_0x4d5565[_0x228f3c(0x21b)][_0x228f3c(0x209)]},_0x4d5565[_0x228f3c(0x21b)][_0x228f3c(0x209)]);}),_0x94c1dc[_0x1743ba(0x21a)]('list')[_0x1743ba(0x1fe)](_0x1743ba(0x20e))[_0x1743ba(0x204)](_0x1743ba(0x203),_0x1743ba(0x208))[_0x1743ba(0x218)](async _0x30d105=>{const _0x201a24=_0x1743ba;let _0xd5a08e=await r(_0x94c1dc,async()=>await _0x4d5565[_0x201a24(0x21b)][_0x201a24(0x210)]());a(_0x94c1dc,_0x30d105,{'entries':_0xd5a08e},o(_0xd5a08e));}),_0x94c1dc['command'](_0x1743ba(0x215))[_0x1743ba(0x1fe)](_0x1743ba(0x1f1))[_0x1743ba(0x20d)]('<key>',_0x1743ba(0x1f8))[_0x1743ba(0x204)](_0x1743ba(0x203),_0x1743ba(0x208))[_0x1743ba(0x218)](async(_0xde8e0e,_0x236bdf)=>{const _0x506901=_0x1743ba;let _0x47f22f=await r(_0x94c1dc,async()=>await _0x4d5565['config'][_0x506901(0x215)]({'key':_0xde8e0e}));i(_0x94c1dc,_0x236bdf,_0x47f22f);}),_0x94c1dc[_0x1743ba(0x21a)](_0x1743ba(0x1f3))['description'](_0x1743ba(0x1fa))[_0x1743ba(0x20d)](_0x1743ba(0x1fb),'registered\x20config\x20key')['argument'](_0x1743ba(0x211),'config\x20value\x20as\x20text')['option'](_0x1743ba(0x203),_0x1743ba(0x208))[_0x1743ba(0x218)](async(_0x4ebb91,_0x4fc190,_0x4cd6cd)=>{const _0x163716=_0x1743ba;let _0x2122bb=await r(_0x94c1dc,async()=>await _0x4d5565[_0x163716(0x21b)][_0x163716(0x1f7)]({'key':_0x4ebb91,'text':_0x4fc190}));i(_0x94c1dc,_0x4cd6cd,_0x2122bb);}),_0x94c1dc['command'](_0x1743ba(0x212))[_0x1743ba(0x1fe)](_0x1743ba(0x1f4))[_0x1743ba(0x20d)](_0x1743ba(0x1fb),_0x1743ba(0x1f8))[_0x1743ba(0x204)](_0x1743ba(0x203),_0x1743ba(0x208))[_0x1743ba(0x218)](async(_0x14f92d,_0x31dc20)=>{const _0x30cc86=_0x1743ba;let _0x5a9bee=await r(_0x94c1dc,async()=>await _0x4d5565['config'][_0x30cc86(0x212)]({'key':_0x14f92d}));i(_0x94c1dc,_0x31dc20,_0x5a9bee);}),_0x94c1dc;}async function r(_0x210870,_0x5276a5){const _0x1bb2ef=_0x331e;try{return await _0x5276a5();}catch(_0xc7155d){throw _0xc7155d instanceof _0xb974c2&&_0x210870[_0x1bb2ef(0x213)](_0xc7155d[_0x1bb2ef(0x201)]+':\x20'+_0xc7155d[_0x1bb2ef(0x1f5)],{'code':_0x1bb2ef(0x217),'exitCode':0x1}),_0xc7155d;}}function i(_0x44f0d8,_0x564a9e,_0x583833){a(_0x44f0d8,_0x564a9e,{'entry':_0x583833},s(_0x583833));}function a(_0x86277,_0x4f1871,_0x513c70,_0x3806e0){const _0x3aaa44=_0x331e;let _0x44be55=_0x4f1871[_0x3aaa44(0x214)]===!0x0?JSON[_0x3aaa44(0x207)](_0x513c70,null,0x2):_0x3806e0;_0x86277['configureOutput']()[_0x3aaa44(0x202)]?.(_0x44be55+'\x0a');}function o(_0xc7a2f){const _0xb61f35=_0x331e;return _0xc7a2f['map'](s)[_0xb61f35(0x20a)]('\x0a');}function _0x12a8(){const _0x3054c1=['Set\x20a\x20registered\x20config\x20entry','<key>','3989560UiktnZ','989890uYqdbk','description','54nCqpOr','15536iBdmLO','code','writeOut','--json','option','281939pXEjvP','1943920uehpgg','stringify','write\x20structured\x20JSON','path','join','366EQODdw','value','argument','List\x20registered\x20config\x20entries','465169qbFqoJ','list','<value>','unset','error','json','get','360frVczD','config.failed','action','\x20=\x20','command','config','113382bqNQLm','Get\x20a\x20registered\x20config\x20entry','Inspect\x20and\x20update\x20application\x20config','set','Remove\x20the\x20explicit\x20value\x20for\x20a\x20registered\x20config\x20entry','message',')\x0a\x20\x20','setFromText','registered\x20config\x20key','source'];_0x12a8=function(){return _0x3054c1;};return _0x12a8();}function s(_0x5aab11){const _0x2b2e12=_0x331e;let _0x5564d5=_0x5aab11[_0x2b2e12(0x1f9)]===_0x2b2e12(0x212)?'<unset>':c(_0x5aab11[_0x2b2e12(0x20c)]);return _0x5aab11['key']+_0x2b2e12(0x219)+_0x5564d5+'\x20('+_0x5aab11[_0x2b2e12(0x1f9)]+_0x2b2e12(0x1f6)+_0x5aab11['description'];}function _0x331e(_0x42bf84,_0xbad0f2){_0x42bf84=_0x42bf84-0x1f1;const _0x12a8c4=_0x12a8();let _0x331eca=_0x12a8c4[_0x42bf84];return _0x331eca;}function c(_0x2d819b){return typeof _0x2d819b=='string'?_0x2d819b:JSON['stringify'](_0x2d819b);}export{n as createConfigCommand};
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@univer-cli/config-command",
3
+ "type": "module",
4
+ "version": "1.0.0-beta.2",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.cjs"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "README.zh-CN.md"
19
+ ],
20
+ "dependencies": {
21
+ "@univer-cli/config": "1.0.0-beta.2"
22
+ },
23
+ "peerDependencies": {
24
+ "commander": "^15.0.0"
25
+ }
26
+ }