@xmorse/cac 6.0.2 → 6.0.3

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/Command.ts CHANGED
@@ -158,9 +158,7 @@ class Command {
158
158
  sections.push({
159
159
  title: 'Commands',
160
160
  body: commands.map(command => {
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}`;
161
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
164
162
  }).join('\n')
165
163
  });
166
164
  sections.push({
package/dist/index.js CHANGED
@@ -364,8 +364,7 @@ class Command {
364
364
  sections.push({
365
365
  title: "Commands",
366
366
  body: commands.map((command) => {
367
- const firstLine = command.description.split("\n")[0].trim();
368
- return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
367
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
369
368
  }).join("\n")
370
369
  });
371
370
  sections.push({
package/dist/index.mjs CHANGED
@@ -1,140 +1,127 @@
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
- };
1
+ import { EventEmitter } from 'events';
26
2
 
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
- });
3
+ function toArr(any) {
4
+ return any == null ? [] : Array.isArray(any) ? any : [any];
5
+ }
130
6
 
131
- // src/CAC.ts
132
- var import_mri = __toModule(require_lib());
133
- import {EventEmitter} from "events";
7
+ function toVal(out, key, val, opts) {
8
+ var x, old=out[key], nxt=(
9
+ !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
10
+ : typeof val === 'boolean' ? val
11
+ : !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
12
+ : (x = +val,x * 0 === 0) ? x : val
13
+ );
14
+ out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
15
+ }
134
16
 
135
- // src/utils.ts
136
- var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
137
- var findAllBrackets = (v) => {
17
+ function mri (args, opts) {
18
+ args = args || [];
19
+ opts = opts || {};
20
+
21
+ var k, arr, arg, name, val, out={ _:[] };
22
+ var i=0, j=0, idx=0, len=args.length;
23
+
24
+ const alibi = opts.alias !== void 0;
25
+ const strict = opts.unknown !== void 0;
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
+ }
110
+
111
+ if (alibi) {
112
+ for (k in out) {
113
+ arr = opts.alias[k] || [];
114
+ while (arr.length > 0) {
115
+ out[arr.shift()] = out[k];
116
+ }
117
+ }
118
+ }
119
+
120
+ return out;
121
+ }
122
+
123
+ const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
124
+ const findAllBrackets = (v) => {
138
125
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
139
126
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
140
127
  const res = [];
@@ -161,7 +148,7 @@ var findAllBrackets = (v) => {
161
148
  }
162
149
  return res;
163
150
  };
164
- var getMriOptions = (options) => {
151
+ const getMriOptions = (options) => {
165
152
  const result = {alias: {}, boolean: []};
166
153
  for (const [index, option] of options.entries()) {
167
154
  if (option.names.length > 1) {
@@ -182,20 +169,20 @@ var getMriOptions = (options) => {
182
169
  }
183
170
  return result;
184
171
  };
185
- var findLongest = (arr) => {
172
+ const findLongest = (arr) => {
186
173
  return arr.sort((a, b) => {
187
174
  return a.length > b.length ? -1 : 1;
188
175
  })[0];
189
176
  };
190
- var padRight = (str, length) => {
177
+ const padRight = (str, length) => {
191
178
  return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
192
179
  };
193
- var camelcase = (input) => {
180
+ const camelcase = (input) => {
194
181
  return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
195
182
  return p1 + p2.toUpperCase();
196
183
  });
197
184
  };
198
- var setDotProp = (obj, keys, val) => {
185
+ const setDotProp = (obj, keys, val) => {
199
186
  let i = 0;
200
187
  let length = keys.length;
201
188
  let t = obj;
@@ -205,7 +192,7 @@ var setDotProp = (obj, keys, val) => {
205
192
  t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
206
193
  }
207
194
  };
208
- var setByType = (obj, transforms) => {
195
+ const setByType = (obj, transforms) => {
209
196
  for (const key of Object.keys(transforms)) {
210
197
  const transform = transforms[key];
211
198
  if (transform.shouldTransform) {
@@ -216,16 +203,16 @@ var setByType = (obj, transforms) => {
216
203
  }
217
204
  }
218
205
  };
219
- var getFileName = (input) => {
206
+ const getFileName = (input) => {
220
207
  const m = /([^\\\/]+)$/.exec(input);
221
208
  return m ? m[1] : "";
222
209
  };
223
- var camelcaseOptionName = (name) => {
210
+ const camelcaseOptionName = (name) => {
224
211
  return name.split(".").map((v, i) => {
225
212
  return i === 0 ? camelcase(v) : v;
226
213
  }).join(".");
227
214
  };
228
- var CACError = class extends Error {
215
+ class CACError extends Error {
229
216
  constructor(message) {
230
217
  super(message);
231
218
  this.name = this.constructor.name;
@@ -235,10 +222,9 @@ var CACError = class extends Error {
235
222
  this.stack = new Error(message).stack;
236
223
  }
237
224
  }
238
- };
225
+ }
239
226
 
240
- // src/Option.ts
241
- var Option = class {
227
+ class Option {
242
228
  constructor(rawName, description, config) {
243
229
  this.rawName = rawName;
244
230
  this.description = description;
@@ -265,15 +251,12 @@ var Option = class {
265
251
  this.isBoolean = true;
266
252
  }
267
253
  }
268
- };
269
- var Option_default = Option;
254
+ }
270
255
 
271
- // src/node.ts
272
- var processArgs = process.argv;
273
- var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
256
+ const processArgs = process.argv;
257
+ const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
274
258
 
275
- // src/Command.ts
276
- var Command = class {
259
+ class Command {
277
260
  constructor(rawName, description, config = {}, cli) {
278
261
  this.rawName = rawName;
279
262
  this.description = description;
@@ -307,7 +290,7 @@ var Command = class {
307
290
  return this;
308
291
  }
309
292
  option(rawName, description, config) {
310
- const option = new Option_default(rawName, description, config);
293
+ const option = new Option(rawName, description, config);
311
294
  this.options.push(option);
312
295
  return this;
313
296
  }
@@ -377,8 +360,7 @@ var Command = class {
377
360
  sections.push({
378
361
  title: "Commands",
379
362
  body: commands.map((command) => {
380
- const firstLine = command.description.split("\n")[0].trim();
381
- return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
363
+ return ` ${padRight(command.rawName, longestCommandName.length)} ${command.description}`;
382
364
  }).join("\n")
383
365
  });
384
366
  sections.push({
@@ -454,16 +436,15 @@ ${section.body}` : section.body;
454
436
  }
455
437
  }
456
438
  }
457
- };
458
- var GlobalCommand = class extends Command {
439
+ }
440
+ class GlobalCommand extends Command {
459
441
  constructor(cli) {
460
442
  super("@@global@@", "", {}, cli);
461
443
  }
462
- };
463
- var Command_default = Command;
444
+ }
464
445
 
465
- // src/CAC.ts
466
- var CAC = class extends EventEmitter {
446
+ var __assign = Object.assign;
447
+ class CAC extends EventEmitter {
467
448
  constructor(name = "") {
468
449
  super();
469
450
  this.name = name;
@@ -479,7 +460,7 @@ var CAC = class extends EventEmitter {
479
460
  return this;
480
461
  }
481
462
  command(rawName, description, config) {
482
- const command = new Command_default(rawName, description || "", config, this);
463
+ const command = new Command(rawName, description || "", config, this);
483
464
  command.globalCommand = this.globalCommand;
484
465
  this.commands.push(command);
485
466
  return command;
@@ -547,10 +528,9 @@ var CAC = class extends EventEmitter {
547
528
  if (result.matched) {
548
529
  shouldParse = false;
549
530
  const matchedCommandName = parsed.args.slice(0, result.consumedArgs).join(" ");
550
- const parsedInfo = {
551
- ...parsed,
531
+ const parsedInfo = __assign(__assign({}, parsed), {
552
532
  args: parsed.args.slice(result.consumedArgs)
553
- };
533
+ });
554
534
  this.setParsedInfo(parsedInfo, command, matchedCommandName);
555
535
  this.emit(`command:${matchedCommandName}`, command);
556
536
  break;
@@ -601,12 +581,11 @@ var CAC = class extends EventEmitter {
601
581
  argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
602
582
  argv = argv.slice(0, doubleDashesIndex);
603
583
  }
604
- let parsed = (0, import_mri.default)(argv, mriOptions);
584
+ let parsed = mri(argv, mriOptions);
605
585
  parsed = Object.keys(parsed).reduce((res, name) => {
606
- return {
607
- ...res,
586
+ return __assign(__assign({}, res), {
608
587
  [camelcaseOptionName(name)]: parsed[name]
609
- };
588
+ });
610
589
  }, {_: []});
611
590
  const args = parsed._;
612
591
  const options = {
@@ -658,15 +637,8 @@ var CAC = class extends EventEmitter {
658
637
  actionArgs.push(options);
659
638
  return command.commandAction.apply(this, actionArgs);
660
639
  }
661
- };
662
- var CAC_default = CAC;
640
+ }
663
641
 
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
- };
642
+ const cac = (name = "") => new CAC(name);
643
+
644
+ export { CAC, Command, cac, cac as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmorse/cac",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "Simple yet powerful framework for building command-line apps.",
5
5
  "repository": {
6
6
  "url": "egoist/cac",