@doracli/commander 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020-2029 zhangzhiguo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # `cli`
2
+
3
+ > @doracli/cli
4
+ 构建功能集合
5
+
6
+ ## Usage
7
+
@@ -0,0 +1 @@
1
+ "use strict";var n=require("commander"),o=function(o){return new n.Command(o)},e=function(n){return function(e){var t=n.command,r=n.description,a=n.action,i=n.help,c=n.options,m=o(t);m.description(r),(c||[]).forEach(function(n){var o=n.name,e=n.simpleName,t=n.description,r=n.type,a=n.defaultValue;m.option("-".concat(e," --").concat(o," ").concat(r),t,a)}),m.action(a),i&&i.onHelp&&m.on("--help",i.onHelp),e.addCommand(m)}};exports.createChildCommand=o,exports.createProgram=function(){return n.program},exports.dealChildOption=e,exports.dealOptions=function(n){return function(o){var t=n.name,r=n.usage,a=n.version,i=n.childCommands;o.name(t),r&&o.usage(r),a&&o.version(a),(i||[]).forEach(function(n){e(n)(o)})}};
@@ -0,0 +1 @@
1
+ import{Command as n,program as o}from"commander";var e=function(o){return new n(o)},t=function(){return o},a=function(n){return function(o){var e=n.name,t=n.usage,a=n.version,i=n.childCommands;o.name(e),t&&o.usage(t),a&&o.version(a),(i||[]).forEach(function(n){c(n)(o)})}},c=function(n){return function(o){var t=n.command,a=n.description,c=n.action,i=n.help,r=n.options,u=e(t);u.description(a),(r||[]).forEach(function(n){var o=n.name,e=n.simpleName,t=n.description,a=n.type,c=n.defaultValue;u.option("-".concat(e," --").concat(o," ").concat(a),t,c)}),u.action(c),i&&i.onHelp&&u.on("--help",i.onHelp),o.addCommand(u)}};export{e as createChildCommand,t as createProgram,c as dealChildOption,a as dealOptions};
@@ -0,0 +1,67 @@
1
+ import * as commander from 'commander';
2
+ import { Command } from 'commander';
3
+ import { TPlainFunction } from '@cclr/lang';
4
+
5
+ declare const createChildCommand: (childComman: string) => Command;
6
+
7
+ /** 获取命令行程序 */
8
+ declare const createProgram: () => commander.Command;
9
+
10
+ type TCommandOptionList = TCommandOption[];
11
+ type TCommandOption = {
12
+ name: string;
13
+ usage?: string;
14
+ version?: string;
15
+ childCommands?: TChildCommandOption[];
16
+ };
17
+ /**
18
+ * 实际会执行的命令
19
+ * @description 带详细配置参数
20
+ */
21
+ type TChildCommandOption = {
22
+ command: string;
23
+ description: string;
24
+ options?: {
25
+ /**
26
+ * 主要命令
27
+ * @description 会自动拼接成 --version
28
+ * @example version
29
+ */
30
+ name: string;
31
+ /**
32
+ * 简写命令
33
+ * @description 会自动拼接成 -V
34
+ * @example V
35
+ */
36
+ simpleName: string;
37
+ /**
38
+ * 参数类型
39
+ * @example undefined -> boolean
40
+ * @example <number> -> 用户输入的值
41
+ * @example [file] -> 可选参数
42
+ */
43
+ type?: string;
44
+ description?: string;
45
+ defaultValue?: string | boolean | number;
46
+ }[];
47
+ action: TPlainFunction;
48
+ help?: {
49
+ onHelp?: () => void;
50
+ };
51
+ };
52
+
53
+ /**
54
+ * 处理命令配置
55
+ * @param options 命令配置
56
+ * @returns
57
+ */
58
+ declare const dealOptions: (options: TCommandOption) => (c: Command) => void;
59
+ /**
60
+ * 处理子命令配置
61
+ * @param option 子命令配置
62
+ * @returns
63
+ */
64
+ declare const dealChildOption: (option: TChildCommandOption) => (c: Command) => void;
65
+
66
+ export { createChildCommand, createProgram, dealChildOption, dealOptions };
67
+ export type { TChildCommandOption, TCommandOption, TCommandOptionList };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@doracli/commander",
3
+ "version": "0.0.1",
4
+ "description": "command line parser",
5
+ "author": "cclr <18843152354@163.com>",
6
+ "homepage": "",
7
+ "license": "MIT",
8
+ "type": "module",
9
+ "exports": {
10
+ "import": "./lib/esm/index.js",
11
+ "require": "./lib/cjs/index.js"
12
+ },
13
+ "types": "lib/type/index.d.ts",
14
+ "directories": {
15
+ "lib": "lib"
16
+ },
17
+ "files": [
18
+ "lib",
19
+ "README.md"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org/"
24
+ },
25
+ "scripts": {
26
+ "test": "vitest",
27
+ "g:test": "vitest run",
28
+ "build": "drn build"
29
+ },
30
+ "dependencies": {
31
+ "@cclr/lang": "^0.1.28",
32
+ "@cclr/utils": "^0.1.28",
33
+ "@doracli/type": "^0.0.1",
34
+ "commander": "^14.0.1"
35
+ },
36
+ "gitHead": "40ab496f25042487a671979074515f3345c96453"
37
+ }