@doracli/commander 0.0.3 → 0.0.4
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 +1 -2
- package/lib/cjs/index.js +46 -1
- package/lib/esm/index.js +49 -1
- package/lib/type/index.d.ts +39 -37
- package/package.json +6 -6
package/README.md
CHANGED
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,46 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
var n = require('commander'),
|
|
3
|
+
o = function (o) {
|
|
4
|
+
return new n.Command(o);
|
|
5
|
+
},
|
|
6
|
+
e = function (n) {
|
|
7
|
+
return function (e) {
|
|
8
|
+
var t = n.command,
|
|
9
|
+
r = n.description,
|
|
10
|
+
a = n.action,
|
|
11
|
+
i = n.help,
|
|
12
|
+
c = n.options,
|
|
13
|
+
m = o(t);
|
|
14
|
+
(m.description(r),
|
|
15
|
+
(c || []).forEach(function (n) {
|
|
16
|
+
var o = n.name,
|
|
17
|
+
e = n.simpleName,
|
|
18
|
+
t = n.description,
|
|
19
|
+
r = n.type,
|
|
20
|
+
a = n.defaultValue;
|
|
21
|
+
m.option('-'.concat(e, ' --').concat(o, ' ').concat(r), t, a);
|
|
22
|
+
}),
|
|
23
|
+
m.action(a),
|
|
24
|
+
i && i.onHelp && m.on('--help', i.onHelp),
|
|
25
|
+
e.addCommand(m));
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
((exports.createChildCommand = o),
|
|
29
|
+
(exports.createProgram = function () {
|
|
30
|
+
return n.program;
|
|
31
|
+
}),
|
|
32
|
+
(exports.dealChildOption = e),
|
|
33
|
+
(exports.dealOptions = function (n) {
|
|
34
|
+
return function (o) {
|
|
35
|
+
var t = n.name,
|
|
36
|
+
r = n.usage,
|
|
37
|
+
a = n.version,
|
|
38
|
+
i = n.childCommands;
|
|
39
|
+
(o.name(t),
|
|
40
|
+
r && o.usage(r),
|
|
41
|
+
a && o.version(a),
|
|
42
|
+
(i || []).forEach(function (n) {
|
|
43
|
+
e(n)(o);
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
}));
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1,49 @@
|
|
|
1
|
-
import{Command as n,program as o
|
|
1
|
+
import { Command as n, program as o } from 'commander';
|
|
2
|
+
var e = function (o) {
|
|
3
|
+
return new n(o);
|
|
4
|
+
},
|
|
5
|
+
t = function () {
|
|
6
|
+
return o;
|
|
7
|
+
},
|
|
8
|
+
a = function (n) {
|
|
9
|
+
return function (o) {
|
|
10
|
+
var e = n.name,
|
|
11
|
+
t = n.usage,
|
|
12
|
+
a = n.version,
|
|
13
|
+
i = n.childCommands;
|
|
14
|
+
(o.name(e),
|
|
15
|
+
t && o.usage(t),
|
|
16
|
+
a && o.version(a),
|
|
17
|
+
(i || []).forEach(function (n) {
|
|
18
|
+
c(n)(o);
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
c = function (n) {
|
|
23
|
+
return function (o) {
|
|
24
|
+
var t = n.command,
|
|
25
|
+
a = n.description,
|
|
26
|
+
c = n.action,
|
|
27
|
+
i = n.help,
|
|
28
|
+
r = n.options,
|
|
29
|
+
u = e(t);
|
|
30
|
+
(u.description(a),
|
|
31
|
+
(r || []).forEach(function (n) {
|
|
32
|
+
var o = n.name,
|
|
33
|
+
e = n.simpleName,
|
|
34
|
+
t = n.description,
|
|
35
|
+
a = n.type,
|
|
36
|
+
c = n.defaultValue;
|
|
37
|
+
u.option('-'.concat(e, ' --').concat(o, ' ').concat(a), t, c);
|
|
38
|
+
}),
|
|
39
|
+
u.action(c),
|
|
40
|
+
i && i.onHelp && u.on('--help', i.onHelp),
|
|
41
|
+
o.addCommand(u));
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export {
|
|
45
|
+
e as createChildCommand,
|
|
46
|
+
t as createProgram,
|
|
47
|
+
c as dealChildOption,
|
|
48
|
+
a as dealOptions,
|
|
49
|
+
};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as commander from 'commander';
|
|
2
|
-
import { Command } from 'commander';
|
|
3
|
-
import { TPlainFunction } from '@cclr/lang';
|
|
1
|
+
import type * as commander from 'commander';
|
|
2
|
+
import type { Command } from 'commander';
|
|
3
|
+
import type { TPlainFunction } from '@cclr/lang';
|
|
4
4
|
|
|
5
5
|
declare const createChildCommand: (childComman: string) => Command;
|
|
6
6
|
|
|
@@ -9,45 +9,45 @@ declare const createProgram: () => commander.Command;
|
|
|
9
9
|
|
|
10
10
|
type TCommandOptionList = TCommandOption[];
|
|
11
11
|
type TCommandOption = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
name: string;
|
|
13
|
+
usage?: string;
|
|
14
|
+
version?: string;
|
|
15
|
+
childCommands?: TChildCommandOption[];
|
|
16
16
|
};
|
|
17
17
|
/**
|
|
18
18
|
* 实际会执行的命令
|
|
19
19
|
* @description 带详细配置参数
|
|
20
20
|
*/
|
|
21
21
|
type TChildCommandOption = {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
51
|
};
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -61,7 +61,9 @@ declare const dealOptions: (options: TCommandOption) => (c: Command) => void;
|
|
|
61
61
|
* @param option 子命令配置
|
|
62
62
|
* @returns
|
|
63
63
|
*/
|
|
64
|
-
declare const dealChildOption: (
|
|
64
|
+
declare const dealChildOption: (
|
|
65
|
+
option: TChildCommandOption
|
|
66
|
+
) => (c: Command) => void;
|
|
65
67
|
|
|
66
68
|
export { createChildCommand, createProgram, dealChildOption, dealOptions };
|
|
67
69
|
export type { TChildCommandOption, TCommandOption, TCommandOptionList };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doracli/commander",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "command line parser",
|
|
5
5
|
"author": "cclr <18843152354@163.com>",
|
|
6
6
|
"homepage": "",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"build": "drn build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@cclr/lang": "^0.1.
|
|
32
|
-
"@cclr/utils": "^0.1.
|
|
33
|
-
"@doracli/type": "^0.0.
|
|
34
|
-
"commander": "^14.0.
|
|
31
|
+
"@cclr/lang": "^0.1.44",
|
|
32
|
+
"@cclr/utils": "^0.1.44",
|
|
33
|
+
"@doracli/type": "^0.0.4",
|
|
34
|
+
"commander": "^14.0.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a978bb7e7b32c192b1eb527dae5f25bbe1a2af86"
|
|
37
37
|
}
|