@xmorse/cac 6.0.0 → 6.0.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/deno/CAC.ts +1 -1
- package/deno/Command.ts +11 -1
- package/dist/index.js +8 -1
- package/dist/index.mjs +187 -153
- package/package.json +12 -11
package/deno/CAC.ts
CHANGED
|
@@ -170,7 +170,7 @@ class CAC extends EventEmitter {
|
|
|
170
170
|
// Search sub-commands
|
|
171
171
|
for (const command of sortedCommands) {
|
|
172
172
|
const parsed = this.mri(argv.slice(2), command);
|
|
173
|
-
const result = command.isMatched(
|
|
173
|
+
const result = command.isMatched(parsed.args as string[]);
|
|
174
174
|
if (result.matched) {
|
|
175
175
|
shouldParse = false;
|
|
176
176
|
const matchedCommandName = parsed.args.slice(0, result.consumedArgs).join(' ');
|
package/deno/Command.ts
CHANGED
|
@@ -144,13 +144,23 @@ class Command {
|
|
|
144
144
|
title: 'Usage',
|
|
145
145
|
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
146
146
|
});
|
|
147
|
+
|
|
148
|
+
// Show full description for specific commands (not global/default)
|
|
149
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
|
|
150
|
+
sections.push({
|
|
151
|
+
title: 'Description',
|
|
152
|
+
body: this.description.split('\n').map(line => ` ${line}`).join('\n')
|
|
153
|
+
});
|
|
154
|
+
}
|
|
147
155
|
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
148
156
|
if (showCommands) {
|
|
149
157
|
const longestCommandName = findLongest(commands.map(command => command.rawName));
|
|
150
158
|
sections.push({
|
|
151
159
|
title: 'Commands',
|
|
152
160
|
body: commands.map(command => {
|
|
153
|
-
|
|
161
|
+
// Only show first line of description in commands listing
|
|
162
|
+
const firstLine = command.description.split('\n')[0].trim();
|
|
163
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
154
164
|
}).join('\n')
|
|
155
165
|
});
|
|
156
166
|
sections.push({
|
package/dist/index.js
CHANGED
|
@@ -352,13 +352,20 @@ class Command {
|
|
|
352
352
|
title: "Usage",
|
|
353
353
|
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
354
354
|
});
|
|
355
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
|
|
356
|
+
sections.push({
|
|
357
|
+
title: "Description",
|
|
358
|
+
body: this.description.split("\n").map((line) => ` ${line}`).join("\n")
|
|
359
|
+
});
|
|
360
|
+
}
|
|
355
361
|
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
356
362
|
if (showCommands) {
|
|
357
363
|
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
358
364
|
sections.push({
|
|
359
365
|
title: "Commands",
|
|
360
366
|
body: commands.map((command) => {
|
|
361
|
-
|
|
367
|
+
const firstLine = command.description.split("\n")[0].trim();
|
|
368
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
362
369
|
}).join("\n")
|
|
363
370
|
});
|
|
364
371
|
sections.push({
|
package/dist/index.mjs
CHANGED
|
@@ -1,127 +1,140 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const defaults = opts.default !== void 0;
|
|
27
|
-
|
|
28
|
-
opts.alias = opts.alias || {};
|
|
29
|
-
opts.string = toArr(opts.string);
|
|
30
|
-
opts.boolean = toArr(opts.boolean);
|
|
31
|
-
|
|
32
|
-
if (alibi) {
|
|
33
|
-
for (k in opts.alias) {
|
|
34
|
-
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
35
|
-
for (i=0; i < arr.length; i++) {
|
|
36
|
-
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (i=opts.boolean.length; i-- > 0;) {
|
|
42
|
-
arr = opts.alias[opts.boolean[i]] || [];
|
|
43
|
-
for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
for (i=opts.string.length; i-- > 0;) {
|
|
47
|
-
arr = opts.alias[opts.string[i]] || [];
|
|
48
|
-
for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (defaults) {
|
|
52
|
-
for (k in opts.default) {
|
|
53
|
-
name = typeof opts.default[k];
|
|
54
|
-
arr = opts.alias[k] = opts.alias[k] || [];
|
|
55
|
-
if (opts[name] !== void 0) {
|
|
56
|
-
opts[name].push(k);
|
|
57
|
-
for (i=0; i < arr.length; i++) {
|
|
58
|
-
opts[name].push(arr[i]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const keys = strict ? Object.keys(opts.alias) : [];
|
|
65
|
-
|
|
66
|
-
for (i=0; i < len; i++) {
|
|
67
|
-
arg = args[i];
|
|
68
|
-
|
|
69
|
-
if (arg === '--') {
|
|
70
|
-
out._ = out._.concat(args.slice(++i));
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
for (j=0; j < arg.length; j++) {
|
|
75
|
-
if (arg.charCodeAt(j) !== 45) break; // "-"
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (j === 0) {
|
|
79
|
-
out._.push(arg);
|
|
80
|
-
} else if (arg.substring(j, j + 3) === 'no-') {
|
|
81
|
-
name = arg.substring(j + 3);
|
|
82
|
-
if (strict && !~keys.indexOf(name)) {
|
|
83
|
-
return opts.unknown(arg);
|
|
84
|
-
}
|
|
85
|
-
out[name] = false;
|
|
86
|
-
} else {
|
|
87
|
-
for (idx=j+1; idx < arg.length; idx++) {
|
|
88
|
-
if (arg.charCodeAt(idx) === 61) break; // "="
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
name = arg.substring(j, idx);
|
|
92
|
-
val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
|
|
93
|
-
arr = (j === 2 ? [name] : name);
|
|
94
|
-
|
|
95
|
-
for (idx=0; idx < arr.length; idx++) {
|
|
96
|
-
name = arr[idx];
|
|
97
|
-
if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
|
|
98
|
-
toVal(out, name, (idx + 1 < arr.length) || val, opts);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (defaults) {
|
|
104
|
-
for (k in opts.default) {
|
|
105
|
-
if (out[k] === void 0) {
|
|
106
|
-
out[k] = opts.default[k];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
|
|
8
|
+
var __commonJS = (callback, module) => () => {
|
|
9
|
+
if (!module) {
|
|
10
|
+
module = {exports: {}};
|
|
11
|
+
callback(module.exports, module);
|
|
12
|
+
}
|
|
13
|
+
return module.exports;
|
|
14
|
+
};
|
|
15
|
+
var __exportStar = (target, module, desc) => {
|
|
16
|
+
if (module && typeof module === "object" || typeof module === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(module))
|
|
18
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
19
|
+
__defProp(target, key, {get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable});
|
|
20
|
+
}
|
|
21
|
+
return target;
|
|
22
|
+
};
|
|
23
|
+
var __toModule = (module) => {
|
|
24
|
+
return __exportStar(__markAsModule(__defProp(module != null ? __create(__getProtoOf(module)) : {}, "default", module && module.__esModule && "default" in module ? {get: () => module.default, enumerable: true} : {value: module, enumerable: true})), module);
|
|
25
|
+
};
|
|
110
26
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
27
|
+
// node_modules/mri/lib/index.js
|
|
28
|
+
var require_lib = __commonJS((exports, module) => {
|
|
29
|
+
function toArr(any) {
|
|
30
|
+
return any == null ? [] : Array.isArray(any) ? any : [any];
|
|
31
|
+
}
|
|
32
|
+
function toVal(out, key, val, opts) {
|
|
33
|
+
var x, old = out[key], nxt = !!~opts.string.indexOf(key) ? val == null || val === true ? "" : String(val) : typeof val === "boolean" ? val : !!~opts.boolean.indexOf(key) ? val === "false" ? false : val === "true" || (out._.push((x = +val, x * 0 === 0) ? x : val), !!val) : (x = +val, x * 0 === 0) ? x : val;
|
|
34
|
+
out[key] = old == null ? nxt : Array.isArray(old) ? old.concat(nxt) : [old, nxt];
|
|
35
|
+
}
|
|
36
|
+
module.exports = function(args, opts) {
|
|
37
|
+
args = args || [];
|
|
38
|
+
opts = opts || {};
|
|
39
|
+
var k, arr, arg, name, val, out = {_: []};
|
|
40
|
+
var i = 0, j = 0, idx = 0, len = args.length;
|
|
41
|
+
const alibi = opts.alias !== void 0;
|
|
42
|
+
const strict = opts.unknown !== void 0;
|
|
43
|
+
const defaults = opts.default !== void 0;
|
|
44
|
+
opts.alias = opts.alias || {};
|
|
45
|
+
opts.string = toArr(opts.string);
|
|
46
|
+
opts.boolean = toArr(opts.boolean);
|
|
47
|
+
if (alibi) {
|
|
48
|
+
for (k in opts.alias) {
|
|
49
|
+
arr = opts.alias[k] = toArr(opts.alias[k]);
|
|
50
|
+
for (i = 0; i < arr.length; i++) {
|
|
51
|
+
(opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
for (i = opts.boolean.length; i-- > 0; ) {
|
|
56
|
+
arr = opts.alias[opts.boolean[i]] || [];
|
|
57
|
+
for (j = arr.length; j-- > 0; )
|
|
58
|
+
opts.boolean.push(arr[j]);
|
|
59
|
+
}
|
|
60
|
+
for (i = opts.string.length; i-- > 0; ) {
|
|
61
|
+
arr = opts.alias[opts.string[i]] || [];
|
|
62
|
+
for (j = arr.length; j-- > 0; )
|
|
63
|
+
opts.string.push(arr[j]);
|
|
64
|
+
}
|
|
65
|
+
if (defaults) {
|
|
66
|
+
for (k in opts.default) {
|
|
67
|
+
name = typeof opts.default[k];
|
|
68
|
+
arr = opts.alias[k] = opts.alias[k] || [];
|
|
69
|
+
if (opts[name] !== void 0) {
|
|
70
|
+
opts[name].push(k);
|
|
71
|
+
for (i = 0; i < arr.length; i++) {
|
|
72
|
+
opts[name].push(arr[i]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const keys = strict ? Object.keys(opts.alias) : [];
|
|
78
|
+
for (i = 0; i < len; i++) {
|
|
79
|
+
arg = args[i];
|
|
80
|
+
if (arg === "--") {
|
|
81
|
+
out._ = out._.concat(args.slice(++i));
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
for (j = 0; j < arg.length; j++) {
|
|
85
|
+
if (arg.charCodeAt(j) !== 45)
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (j === 0) {
|
|
89
|
+
out._.push(arg);
|
|
90
|
+
} else if (arg.substring(j, j + 3) === "no-") {
|
|
91
|
+
name = arg.substring(j + 3);
|
|
92
|
+
if (strict && !~keys.indexOf(name)) {
|
|
93
|
+
return opts.unknown(arg);
|
|
94
|
+
}
|
|
95
|
+
out[name] = false;
|
|
96
|
+
} else {
|
|
97
|
+
for (idx = j + 1; idx < arg.length; idx++) {
|
|
98
|
+
if (arg.charCodeAt(idx) === 61)
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
name = arg.substring(j, idx);
|
|
102
|
+
val = arg.substring(++idx) || (i + 1 === len || ("" + args[i + 1]).charCodeAt(0) === 45 || args[++i]);
|
|
103
|
+
arr = j === 2 ? [name] : name;
|
|
104
|
+
for (idx = 0; idx < arr.length; idx++) {
|
|
105
|
+
name = arr[idx];
|
|
106
|
+
if (strict && !~keys.indexOf(name))
|
|
107
|
+
return opts.unknown("-".repeat(j) + name);
|
|
108
|
+
toVal(out, name, idx + 1 < arr.length || val, opts);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (defaults) {
|
|
113
|
+
for (k in opts.default) {
|
|
114
|
+
if (out[k] === void 0) {
|
|
115
|
+
out[k] = opts.default[k];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (alibi) {
|
|
120
|
+
for (k in out) {
|
|
121
|
+
arr = opts.alias[k] || [];
|
|
122
|
+
while (arr.length > 0) {
|
|
123
|
+
out[arr.shift()] = out[k];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
};
|
|
129
|
+
});
|
|
119
130
|
|
|
120
|
-
|
|
121
|
-
|
|
131
|
+
// src/CAC.ts
|
|
132
|
+
var import_mri = __toModule(require_lib());
|
|
133
|
+
import {EventEmitter} from "events";
|
|
122
134
|
|
|
123
|
-
|
|
124
|
-
|
|
135
|
+
// src/utils.ts
|
|
136
|
+
var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
|
|
137
|
+
var findAllBrackets = (v) => {
|
|
125
138
|
const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
|
|
126
139
|
const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
|
|
127
140
|
const res = [];
|
|
@@ -148,7 +161,7 @@ const findAllBrackets = (v) => {
|
|
|
148
161
|
}
|
|
149
162
|
return res;
|
|
150
163
|
};
|
|
151
|
-
|
|
164
|
+
var getMriOptions = (options) => {
|
|
152
165
|
const result = {alias: {}, boolean: []};
|
|
153
166
|
for (const [index, option] of options.entries()) {
|
|
154
167
|
if (option.names.length > 1) {
|
|
@@ -169,20 +182,20 @@ const getMriOptions = (options) => {
|
|
|
169
182
|
}
|
|
170
183
|
return result;
|
|
171
184
|
};
|
|
172
|
-
|
|
185
|
+
var findLongest = (arr) => {
|
|
173
186
|
return arr.sort((a, b) => {
|
|
174
187
|
return a.length > b.length ? -1 : 1;
|
|
175
188
|
})[0];
|
|
176
189
|
};
|
|
177
|
-
|
|
190
|
+
var padRight = (str, length) => {
|
|
178
191
|
return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
|
|
179
192
|
};
|
|
180
|
-
|
|
193
|
+
var camelcase = (input) => {
|
|
181
194
|
return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
|
|
182
195
|
return p1 + p2.toUpperCase();
|
|
183
196
|
});
|
|
184
197
|
};
|
|
185
|
-
|
|
198
|
+
var setDotProp = (obj, keys, val) => {
|
|
186
199
|
let i = 0;
|
|
187
200
|
let length = keys.length;
|
|
188
201
|
let t = obj;
|
|
@@ -192,7 +205,7 @@ const setDotProp = (obj, keys, val) => {
|
|
|
192
205
|
t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
|
|
193
206
|
}
|
|
194
207
|
};
|
|
195
|
-
|
|
208
|
+
var setByType = (obj, transforms) => {
|
|
196
209
|
for (const key of Object.keys(transforms)) {
|
|
197
210
|
const transform = transforms[key];
|
|
198
211
|
if (transform.shouldTransform) {
|
|
@@ -203,16 +216,16 @@ const setByType = (obj, transforms) => {
|
|
|
203
216
|
}
|
|
204
217
|
}
|
|
205
218
|
};
|
|
206
|
-
|
|
219
|
+
var getFileName = (input) => {
|
|
207
220
|
const m = /([^\\\/]+)$/.exec(input);
|
|
208
221
|
return m ? m[1] : "";
|
|
209
222
|
};
|
|
210
|
-
|
|
223
|
+
var camelcaseOptionName = (name) => {
|
|
211
224
|
return name.split(".").map((v, i) => {
|
|
212
225
|
return i === 0 ? camelcase(v) : v;
|
|
213
226
|
}).join(".");
|
|
214
227
|
};
|
|
215
|
-
|
|
228
|
+
var CACError = class extends Error {
|
|
216
229
|
constructor(message) {
|
|
217
230
|
super(message);
|
|
218
231
|
this.name = this.constructor.name;
|
|
@@ -222,9 +235,10 @@ class CACError extends Error {
|
|
|
222
235
|
this.stack = new Error(message).stack;
|
|
223
236
|
}
|
|
224
237
|
}
|
|
225
|
-
}
|
|
238
|
+
};
|
|
226
239
|
|
|
227
|
-
|
|
240
|
+
// src/Option.ts
|
|
241
|
+
var Option = class {
|
|
228
242
|
constructor(rawName, description, config) {
|
|
229
243
|
this.rawName = rawName;
|
|
230
244
|
this.description = description;
|
|
@@ -251,12 +265,15 @@ class Option {
|
|
|
251
265
|
this.isBoolean = true;
|
|
252
266
|
}
|
|
253
267
|
}
|
|
254
|
-
}
|
|
268
|
+
};
|
|
269
|
+
var Option_default = Option;
|
|
255
270
|
|
|
256
|
-
|
|
257
|
-
|
|
271
|
+
// src/node.ts
|
|
272
|
+
var processArgs = process.argv;
|
|
273
|
+
var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
258
274
|
|
|
259
|
-
|
|
275
|
+
// src/Command.ts
|
|
276
|
+
var Command = class {
|
|
260
277
|
constructor(rawName, description, config = {}, cli) {
|
|
261
278
|
this.rawName = rawName;
|
|
262
279
|
this.description = description;
|
|
@@ -290,7 +307,7 @@ class Command {
|
|
|
290
307
|
return this;
|
|
291
308
|
}
|
|
292
309
|
option(rawName, description, config) {
|
|
293
|
-
const option = new
|
|
310
|
+
const option = new Option_default(rawName, description, config);
|
|
294
311
|
this.options.push(option);
|
|
295
312
|
return this;
|
|
296
313
|
}
|
|
@@ -348,13 +365,20 @@ class Command {
|
|
|
348
365
|
title: "Usage",
|
|
349
366
|
body: ` $ ${name} ${this.usageText || this.rawName}`
|
|
350
367
|
});
|
|
368
|
+
if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
|
|
369
|
+
sections.push({
|
|
370
|
+
title: "Description",
|
|
371
|
+
body: this.description.split("\n").map((line) => ` ${line}`).join("\n")
|
|
372
|
+
});
|
|
373
|
+
}
|
|
351
374
|
const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
|
|
352
375
|
if (showCommands) {
|
|
353
376
|
const longestCommandName = findLongest(commands.map((command) => command.rawName));
|
|
354
377
|
sections.push({
|
|
355
378
|
title: "Commands",
|
|
356
379
|
body: commands.map((command) => {
|
|
357
|
-
|
|
380
|
+
const firstLine = command.description.split("\n")[0].trim();
|
|
381
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
358
382
|
}).join("\n")
|
|
359
383
|
});
|
|
360
384
|
sections.push({
|
|
@@ -430,15 +454,16 @@ ${section.body}` : section.body;
|
|
|
430
454
|
}
|
|
431
455
|
}
|
|
432
456
|
}
|
|
433
|
-
}
|
|
434
|
-
|
|
457
|
+
};
|
|
458
|
+
var GlobalCommand = class extends Command {
|
|
435
459
|
constructor(cli) {
|
|
436
460
|
super("@@global@@", "", {}, cli);
|
|
437
461
|
}
|
|
438
|
-
}
|
|
462
|
+
};
|
|
463
|
+
var Command_default = Command;
|
|
439
464
|
|
|
440
|
-
|
|
441
|
-
|
|
465
|
+
// src/CAC.ts
|
|
466
|
+
var CAC = class extends EventEmitter {
|
|
442
467
|
constructor(name = "") {
|
|
443
468
|
super();
|
|
444
469
|
this.name = name;
|
|
@@ -454,7 +479,7 @@ class CAC extends EventEmitter {
|
|
|
454
479
|
return this;
|
|
455
480
|
}
|
|
456
481
|
command(rawName, description, config) {
|
|
457
|
-
const command = new
|
|
482
|
+
const command = new Command_default(rawName, description || "", config, this);
|
|
458
483
|
command.globalCommand = this.globalCommand;
|
|
459
484
|
this.commands.push(command);
|
|
460
485
|
return command;
|
|
@@ -522,9 +547,10 @@ class CAC extends EventEmitter {
|
|
|
522
547
|
if (result.matched) {
|
|
523
548
|
shouldParse = false;
|
|
524
549
|
const matchedCommandName = parsed.args.slice(0, result.consumedArgs).join(" ");
|
|
525
|
-
const parsedInfo =
|
|
550
|
+
const parsedInfo = {
|
|
551
|
+
...parsed,
|
|
526
552
|
args: parsed.args.slice(result.consumedArgs)
|
|
527
|
-
}
|
|
553
|
+
};
|
|
528
554
|
this.setParsedInfo(parsedInfo, command, matchedCommandName);
|
|
529
555
|
this.emit(`command:${matchedCommandName}`, command);
|
|
530
556
|
break;
|
|
@@ -575,11 +601,12 @@ class CAC extends EventEmitter {
|
|
|
575
601
|
argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
|
|
576
602
|
argv = argv.slice(0, doubleDashesIndex);
|
|
577
603
|
}
|
|
578
|
-
let parsed =
|
|
604
|
+
let parsed = (0, import_mri.default)(argv, mriOptions);
|
|
579
605
|
parsed = Object.keys(parsed).reduce((res, name) => {
|
|
580
|
-
return
|
|
606
|
+
return {
|
|
607
|
+
...res,
|
|
581
608
|
[camelcaseOptionName(name)]: parsed[name]
|
|
582
|
-
}
|
|
609
|
+
};
|
|
583
610
|
}, {_: []});
|
|
584
611
|
const args = parsed._;
|
|
585
612
|
const options = {
|
|
@@ -631,8 +658,15 @@ class CAC extends EventEmitter {
|
|
|
631
658
|
actionArgs.push(options);
|
|
632
659
|
return command.commandAction.apply(this, actionArgs);
|
|
633
660
|
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
|
-
const cac = (name = "") => new CAC(name);
|
|
661
|
+
};
|
|
662
|
+
var CAC_default = CAC;
|
|
637
663
|
|
|
638
|
-
|
|
664
|
+
// src/index.ts
|
|
665
|
+
var cac = (name = "") => new CAC_default(name);
|
|
666
|
+
var src_default = cac;
|
|
667
|
+
export {
|
|
668
|
+
CAC_default as CAC,
|
|
669
|
+
Command_default as Command,
|
|
670
|
+
cac,
|
|
671
|
+
src_default as default
|
|
672
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xmorse/cac",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "Simple yet powerful framework for building command-line apps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "egoist/cac",
|
|
@@ -26,6 +26,16 @@
|
|
|
26
26
|
"/deno",
|
|
27
27
|
"/index-compat.js"
|
|
28
28
|
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "jest",
|
|
31
|
+
"test:cov": "jest --coverage",
|
|
32
|
+
"build:deno": "node -r sucrase/register scripts/build-deno.ts",
|
|
33
|
+
"build:node": "rollup -c",
|
|
34
|
+
"build": "npm run build:deno && npm run build:node",
|
|
35
|
+
"toc": "markdown-toc -i README.md",
|
|
36
|
+
"prepublishOnly": "npm run build && cp mod.js mod.mjs",
|
|
37
|
+
"docs:api": "typedoc --out api-doc --readme none --exclude \"**/__test__/**\" --theme minimal"
|
|
38
|
+
},
|
|
29
39
|
"author": "egoist <0x142857@gmail.com>",
|
|
30
40
|
"license": "MIT",
|
|
31
41
|
"devDependencies": {
|
|
@@ -90,14 +100,5 @@
|
|
|
90
100
|
"hooks": {
|
|
91
101
|
"pre-commit": "npm t && lint-staged"
|
|
92
102
|
}
|
|
93
|
-
},
|
|
94
|
-
"scripts": {
|
|
95
|
-
"test": "jest",
|
|
96
|
-
"test:cov": "jest --coverage",
|
|
97
|
-
"build:deno": "node -r sucrase/register scripts/build-deno.ts",
|
|
98
|
-
"build:node": "rollup -c",
|
|
99
|
-
"build": "yarn build:deno && yarn build:node",
|
|
100
|
-
"toc": "markdown-toc -i README.md",
|
|
101
|
-
"docs:api": "typedoc --out api-doc --readme none --exclude \"**/__test__/**\" --theme minimal"
|
|
102
103
|
}
|
|
103
|
-
}
|
|
104
|
+
}
|