@xmorse/cac 6.0.1 → 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 CHANGED
@@ -160,18 +160,27 @@ class CAC extends EventEmitter {
160
160
  }
161
161
  let shouldParse = true;
162
162
 
163
+ // Sort by name length (longest first) so "mcp login" matches before "mcp"
164
+ const sortedCommands = [...this.commands].sort((a, b) => {
165
+ const aLength = a.name.split(' ').filter(Boolean).length;
166
+ const bLength = b.name.split(' ').filter(Boolean).length;
167
+ return bLength - aLength;
168
+ });
169
+
163
170
  // Search sub-commands
164
- for (const command of this.commands) {
171
+ for (const command of sortedCommands) {
165
172
  const parsed = this.mri(argv.slice(2), command);
166
- const commandName = parsed.args[0];
167
- if (command.isMatched(commandName)) {
173
+ const result = command.isMatched(parsed.args as string[]);
174
+ if (result.matched) {
168
175
  shouldParse = false;
176
+ const matchedCommandName = parsed.args.slice(0, result.consumedArgs).join(' ');
169
177
  const parsedInfo = {
170
178
  ...parsed,
171
- args: parsed.args.slice(1)
179
+ args: parsed.args.slice(result.consumedArgs)
172
180
  };
173
- this.setParsedInfo(parsedInfo, command, commandName);
174
- this.emit(`command:${commandName}`, command);
181
+ this.setParsedInfo(parsedInfo, command, matchedCommandName);
182
+ this.emit(`command:${matchedCommandName}`, command);
183
+ break; // Stop after first match (greedy matching)
175
184
  }
176
185
  }
177
186
  if (shouldParse) {
package/deno/Command.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import CAC from "./CAC.ts";
2
2
  import Option, { OptionConfig } from "./Option.ts";
3
- import { removeBrackets, findAllBrackets, findLongest, padRight, CACError, wrapText } from "./utils.ts";
3
+ import { removeBrackets, findAllBrackets, findLongest, padRight, CACError } from "./utils.ts";
4
4
  import { platformInfo } from "./deno.ts";
5
5
  interface CommandArg {
6
6
  required: boolean;
@@ -77,13 +77,38 @@ class Command {
77
77
  this.commandAction = callback;
78
78
  return this;
79
79
  }
80
-
81
- /**
82
- * Check if a command name is matched by this command
83
- * @param name Command name
84
- */
85
- isMatched(name: string) {
86
- return this.name === name || this.aliasNames.includes(name);
80
+ isMatched(args: string[]): {
81
+ matched: boolean;
82
+ consumedArgs: number;
83
+ } {
84
+ const nameParts = this.name.split(' ').filter(Boolean);
85
+ if (nameParts.length === 0) {
86
+ return {
87
+ matched: false,
88
+ consumedArgs: 0
89
+ };
90
+ }
91
+ if (args.length < nameParts.length) {
92
+ return {
93
+ matched: false,
94
+ consumedArgs: 0
95
+ };
96
+ }
97
+ for (let i = 0; i < nameParts.length; i++) {
98
+ if (nameParts[i] !== args[i]) {
99
+ if (i === 0 && this.aliasNames.includes(args[i])) {
100
+ continue;
101
+ }
102
+ return {
103
+ matched: false,
104
+ consumedArgs: 0
105
+ };
106
+ }
107
+ }
108
+ return {
109
+ matched: true,
110
+ consumedArgs: nameParts.length
111
+ };
87
112
  }
88
113
  get isDefaultCommand() {
89
114
  return this.name === '' || this.aliasNames.includes('!');
@@ -120,12 +145,11 @@ class Command {
120
145
  body: ` $ ${name} ${this.usageText || this.rawName}`
121
146
  });
122
147
 
123
- // Show description for specific commands (not global/default)
148
+ // Show full description for specific commands (not global/default)
124
149
  if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
125
- const terminalWidth = process.stdout?.columns || 80;
126
150
  sections.push({
127
151
  title: 'Description',
128
- body: wrapText(this.description, terminalWidth)
152
+ body: this.description.split('\n').map(line => ` ${line}`).join('\n')
129
153
  });
130
154
  }
131
155
  const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
package/deno/utils.ts CHANGED
@@ -126,44 +126,4 @@ export class CACError extends Error {
126
126
  this.stack = new Error(message).stack;
127
127
  }
128
128
  }
129
- }
130
-
131
- /**
132
- * Wrap text to fit within a given width, preserving existing line breaks
133
- * and special formatting (lists, code blocks, etc.)
134
- */
135
- export const wrapText = (text: string, width = 80, indent = ' '): string => {
136
- const lines = text.split('\n');
137
- const result: string[] = [];
138
- for (const line of lines) {
139
- // Preserve empty lines
140
- if (line.trim() === '') {
141
- result.push('');
142
- continue;
143
- }
144
-
145
- // Preserve lines that start with special chars (bullets, headers, code, indented)
146
- if (/^(\s*[-*>#`]|\s{4,}|#{1,6}\s)/.test(line)) {
147
- result.push(indent + line);
148
- continue;
149
- }
150
-
151
- // Wrap normal paragraphs
152
- const words = line.split(' ');
153
- let currentLine = indent;
154
- for (const word of words) {
155
- if (currentLine.length + word.length + 1 > width) {
156
- if (currentLine.trim()) {
157
- result.push(currentLine);
158
- }
159
- currentLine = indent + word;
160
- } else {
161
- currentLine = currentLine === indent ? indent + word : `${currentLine} ${word}`;
162
- }
163
- }
164
- if (currentLine.trim()) {
165
- result.push(currentLine);
166
- }
167
- }
168
- return result.join('\n');
169
- };
129
+ }
package/dist/index.js CHANGED
@@ -4,37 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var events = require('events');
6
6
 
7
- function wrapText(text, width = 80, indent = ' ') {
8
- const lines = text.split('\n');
9
- const result = [];
10
- for (const line of lines) {
11
- if (line.trim() === '') {
12
- result.push('');
13
- continue;
14
- }
15
- if (/^(\s*[-*>#`]|\s{4,}|#{1,6}\s)/.test(line)) {
16
- result.push(indent + line);
17
- continue;
18
- }
19
- const words = line.split(' ');
20
- let currentLine = indent;
21
- for (const word of words) {
22
- if (currentLine.length + word.length + 1 > width) {
23
- if (currentLine.trim()) {
24
- result.push(currentLine);
25
- }
26
- currentLine = indent + word;
27
- } else {
28
- currentLine = currentLine === indent ? indent + word : `${currentLine} ${word}`;
29
- }
30
- }
31
- if (currentLine.trim()) {
32
- result.push(currentLine);
33
- }
34
- }
35
- return result.join('\n');
36
- }
37
-
38
7
  function toArr(any) {
39
8
  return any == null ? [] : Array.isArray(any) ? any : [any];
40
9
  }
@@ -384,10 +353,9 @@ class Command {
384
353
  body: ` $ ${name} ${this.usageText || this.rawName}`
385
354
  });
386
355
  if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
387
- const terminalWidth = process.stdout?.columns || 80;
388
356
  sections.push({
389
357
  title: "Description",
390
- body: wrapText(this.description, terminalWidth)
358
+ body: this.description.split("\n").map((line) => ` ${line}`).join("\n")
391
359
  });
392
360
  }
393
361
  const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
@@ -396,7 +364,7 @@ class Command {
396
364
  sections.push({
397
365
  title: "Commands",
398
366
  body: commands.map((command) => {
399
- const firstLine = command.description.split('\n')[0].trim();
367
+ const firstLine = command.description.split("\n")[0].trim();
400
368
  return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
401
369
  }).join("\n")
402
370
  });
package/dist/index.mjs CHANGED
@@ -1,158 +1,140 @@
1
- import { EventEmitter } from 'events';
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
+ };
2
26
 
3
- function wrapText(text, width = 80, indent = ' ') {
4
- const lines = text.split('\n');
5
- const result = [];
6
- for (const line of lines) {
7
- if (line.trim() === '') {
8
- result.push('');
9
- continue;
10
- }
11
- if (/^(\s*[-*>#`]|\s{4,}|#{1,6}\s)/.test(line)) {
12
- result.push(indent + line);
13
- continue;
14
- }
15
- const words = line.split(' ');
16
- let currentLine = indent;
17
- for (const word of words) {
18
- if (currentLine.length + word.length + 1 > width) {
19
- if (currentLine.trim()) {
20
- result.push(currentLine);
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);
21
94
  }
22
- currentLine = indent + word;
95
+ out[name] = false;
23
96
  } else {
24
- currentLine = currentLine === indent ? indent + word : `${currentLine} ${word}`;
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
+ }
25
110
  }
26
111
  }
27
- if (currentLine.trim()) {
28
- result.push(currentLine);
112
+ if (defaults) {
113
+ for (k in opts.default) {
114
+ if (out[k] === void 0) {
115
+ out[k] = opts.default[k];
116
+ }
117
+ }
29
118
  }
30
- }
31
- return result.join('\n');
32
- }
33
-
34
- function toArr(any) {
35
- return any == null ? [] : Array.isArray(any) ? any : [any];
36
- }
37
-
38
- function toVal(out, key, val, opts) {
39
- var x, old=out[key], nxt=(
40
- !!~opts.string.indexOf(key) ? (val == null || val === true ? '' : String(val))
41
- : typeof val === 'boolean' ? val
42
- : !!~opts.boolean.indexOf(key) ? (val === 'false' ? false : val === 'true' || (out._.push((x = +val,x * 0 === 0) ? x : val),!!val))
43
- : (x = +val,x * 0 === 0) ? x : val
44
- );
45
- out[key] = old == null ? nxt : (Array.isArray(old) ? old.concat(nxt) : [old, nxt]);
46
- }
47
-
48
- function mri (args, opts) {
49
- args = args || [];
50
- opts = opts || {};
51
-
52
- var k, arr, arg, name, val, out={ _:[] };
53
- var i=0, j=0, idx=0, len=args.length;
54
-
55
- const alibi = opts.alias !== void 0;
56
- const strict = opts.unknown !== void 0;
57
- const defaults = opts.default !== void 0;
58
-
59
- opts.alias = opts.alias || {};
60
- opts.string = toArr(opts.string);
61
- opts.boolean = toArr(opts.boolean);
62
-
63
- if (alibi) {
64
- for (k in opts.alias) {
65
- arr = opts.alias[k] = toArr(opts.alias[k]);
66
- for (i=0; i < arr.length; i++) {
67
- (opts.alias[arr[i]] = arr.concat(k)).splice(i, 1);
68
- }
69
- }
70
- }
71
-
72
- for (i=opts.boolean.length; i-- > 0;) {
73
- arr = opts.alias[opts.boolean[i]] || [];
74
- for (j=arr.length; j-- > 0;) opts.boolean.push(arr[j]);
75
- }
76
-
77
- for (i=opts.string.length; i-- > 0;) {
78
- arr = opts.alias[opts.string[i]] || [];
79
- for (j=arr.length; j-- > 0;) opts.string.push(arr[j]);
80
- }
81
-
82
- if (defaults) {
83
- for (k in opts.default) {
84
- name = typeof opts.default[k];
85
- arr = opts.alias[k] = opts.alias[k] || [];
86
- if (opts[name] !== void 0) {
87
- opts[name].push(k);
88
- for (i=0; i < arr.length; i++) {
89
- opts[name].push(arr[i]);
90
- }
91
- }
92
- }
93
- }
94
-
95
- const keys = strict ? Object.keys(opts.alias) : [];
96
-
97
- for (i=0; i < len; i++) {
98
- arg = args[i];
99
-
100
- if (arg === '--') {
101
- out._ = out._.concat(args.slice(++i));
102
- break;
103
- }
104
-
105
- for (j=0; j < arg.length; j++) {
106
- if (arg.charCodeAt(j) !== 45) break; // "-"
107
- }
108
-
109
- if (j === 0) {
110
- out._.push(arg);
111
- } else if (arg.substring(j, j + 3) === 'no-') {
112
- name = arg.substring(j + 3);
113
- if (strict && !~keys.indexOf(name)) {
114
- return opts.unknown(arg);
115
- }
116
- out[name] = false;
117
- } else {
118
- for (idx=j+1; idx < arg.length; idx++) {
119
- if (arg.charCodeAt(idx) === 61) break; // "="
120
- }
121
-
122
- name = arg.substring(j, idx);
123
- val = arg.substring(++idx) || (i+1 === len || (''+args[i+1]).charCodeAt(0) === 45 || args[++i]);
124
- arr = (j === 2 ? [name] : name);
125
-
126
- for (idx=0; idx < arr.length; idx++) {
127
- name = arr[idx];
128
- if (strict && !~keys.indexOf(name)) return opts.unknown('-'.repeat(j) + name);
129
- toVal(out, name, (idx + 1 < arr.length) || val, opts);
130
- }
131
- }
132
- }
133
-
134
- if (defaults) {
135
- for (k in opts.default) {
136
- if (out[k] === void 0) {
137
- out[k] = opts.default[k];
138
- }
139
- }
140
- }
141
-
142
- if (alibi) {
143
- for (k in out) {
144
- arr = opts.alias[k] || [];
145
- while (arr.length > 0) {
146
- out[arr.shift()] = out[k];
147
- }
148
- }
149
- }
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
+ });
150
130
 
151
- return out;
152
- }
131
+ // src/CAC.ts
132
+ var import_mri = __toModule(require_lib());
133
+ import {EventEmitter} from "events";
153
134
 
154
- const removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
155
- const findAllBrackets = (v) => {
135
+ // src/utils.ts
136
+ var removeBrackets = (v) => v.replace(/[<[].+/, "").trim();
137
+ var findAllBrackets = (v) => {
156
138
  const ANGLED_BRACKET_RE_GLOBAL = /<([^>]+)>/g;
157
139
  const SQUARE_BRACKET_RE_GLOBAL = /\[([^\]]+)\]/g;
158
140
  const res = [];
@@ -179,7 +161,7 @@ const findAllBrackets = (v) => {
179
161
  }
180
162
  return res;
181
163
  };
182
- const getMriOptions = (options) => {
164
+ var getMriOptions = (options) => {
183
165
  const result = {alias: {}, boolean: []};
184
166
  for (const [index, option] of options.entries()) {
185
167
  if (option.names.length > 1) {
@@ -200,20 +182,20 @@ const getMriOptions = (options) => {
200
182
  }
201
183
  return result;
202
184
  };
203
- const findLongest = (arr) => {
185
+ var findLongest = (arr) => {
204
186
  return arr.sort((a, b) => {
205
187
  return a.length > b.length ? -1 : 1;
206
188
  })[0];
207
189
  };
208
- const padRight = (str, length) => {
190
+ var padRight = (str, length) => {
209
191
  return str.length >= length ? str : `${str}${" ".repeat(length - str.length)}`;
210
192
  };
211
- const camelcase = (input) => {
193
+ var camelcase = (input) => {
212
194
  return input.replace(/([a-z])-([a-z])/g, (_, p1, p2) => {
213
195
  return p1 + p2.toUpperCase();
214
196
  });
215
197
  };
216
- const setDotProp = (obj, keys, val) => {
198
+ var setDotProp = (obj, keys, val) => {
217
199
  let i = 0;
218
200
  let length = keys.length;
219
201
  let t = obj;
@@ -223,7 +205,7 @@ const setDotProp = (obj, keys, val) => {
223
205
  t = t[keys[i]] = i === length - 1 ? val : x != null ? x : !!~keys[i + 1].indexOf(".") || !(+keys[i + 1] > -1) ? {} : [];
224
206
  }
225
207
  };
226
- const setByType = (obj, transforms) => {
208
+ var setByType = (obj, transforms) => {
227
209
  for (const key of Object.keys(transforms)) {
228
210
  const transform = transforms[key];
229
211
  if (transform.shouldTransform) {
@@ -234,16 +216,16 @@ const setByType = (obj, transforms) => {
234
216
  }
235
217
  }
236
218
  };
237
- const getFileName = (input) => {
219
+ var getFileName = (input) => {
238
220
  const m = /([^\\\/]+)$/.exec(input);
239
221
  return m ? m[1] : "";
240
222
  };
241
- const camelcaseOptionName = (name) => {
223
+ var camelcaseOptionName = (name) => {
242
224
  return name.split(".").map((v, i) => {
243
225
  return i === 0 ? camelcase(v) : v;
244
226
  }).join(".");
245
227
  };
246
- class CACError extends Error {
228
+ var CACError = class extends Error {
247
229
  constructor(message) {
248
230
  super(message);
249
231
  this.name = this.constructor.name;
@@ -253,9 +235,10 @@ class CACError extends Error {
253
235
  this.stack = new Error(message).stack;
254
236
  }
255
237
  }
256
- }
238
+ };
257
239
 
258
- class Option {
240
+ // src/Option.ts
241
+ var Option = class {
259
242
  constructor(rawName, description, config) {
260
243
  this.rawName = rawName;
261
244
  this.description = description;
@@ -282,12 +265,15 @@ class Option {
282
265
  this.isBoolean = true;
283
266
  }
284
267
  }
285
- }
268
+ };
269
+ var Option_default = Option;
286
270
 
287
- const processArgs = process.argv;
288
- const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
271
+ // src/node.ts
272
+ var processArgs = process.argv;
273
+ var platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
289
274
 
290
- class Command {
275
+ // src/Command.ts
276
+ var Command = class {
291
277
  constructor(rawName, description, config = {}, cli) {
292
278
  this.rawName = rawName;
293
279
  this.description = description;
@@ -321,7 +307,7 @@ class Command {
321
307
  return this;
322
308
  }
323
309
  option(rawName, description, config) {
324
- const option = new Option(rawName, description, config);
310
+ const option = new Option_default(rawName, description, config);
325
311
  this.options.push(option);
326
312
  return this;
327
313
  }
@@ -380,10 +366,9 @@ class Command {
380
366
  body: ` $ ${name} ${this.usageText || this.rawName}`
381
367
  });
382
368
  if (!this.isGlobalCommand && !this.isDefaultCommand && this.description) {
383
- const terminalWidth = process.stdout?.columns || 80;
384
369
  sections.push({
385
370
  title: "Description",
386
- body: wrapText(this.description, terminalWidth)
371
+ body: this.description.split("\n").map((line) => ` ${line}`).join("\n")
387
372
  });
388
373
  }
389
374
  const showCommands = (this.isGlobalCommand || this.isDefaultCommand) && commands.length > 0;
@@ -392,7 +377,7 @@ class Command {
392
377
  sections.push({
393
378
  title: "Commands",
394
379
  body: commands.map((command) => {
395
- const firstLine = command.description.split('\n')[0].trim();
380
+ const firstLine = command.description.split("\n")[0].trim();
396
381
  return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
397
382
  }).join("\n")
398
383
  });
@@ -469,15 +454,16 @@ ${section.body}` : section.body;
469
454
  }
470
455
  }
471
456
  }
472
- }
473
- class GlobalCommand extends Command {
457
+ };
458
+ var GlobalCommand = class extends Command {
474
459
  constructor(cli) {
475
460
  super("@@global@@", "", {}, cli);
476
461
  }
477
- }
462
+ };
463
+ var Command_default = Command;
478
464
 
479
- var __assign = Object.assign;
480
- class CAC extends EventEmitter {
465
+ // src/CAC.ts
466
+ var CAC = class extends EventEmitter {
481
467
  constructor(name = "") {
482
468
  super();
483
469
  this.name = name;
@@ -493,7 +479,7 @@ class CAC extends EventEmitter {
493
479
  return this;
494
480
  }
495
481
  command(rawName, description, config) {
496
- const command = new Command(rawName, description || "", config, this);
482
+ const command = new Command_default(rawName, description || "", config, this);
497
483
  command.globalCommand = this.globalCommand;
498
484
  this.commands.push(command);
499
485
  return command;
@@ -561,9 +547,10 @@ class CAC extends EventEmitter {
561
547
  if (result.matched) {
562
548
  shouldParse = false;
563
549
  const matchedCommandName = parsed.args.slice(0, result.consumedArgs).join(" ");
564
- const parsedInfo = __assign(__assign({}, parsed), {
550
+ const parsedInfo = {
551
+ ...parsed,
565
552
  args: parsed.args.slice(result.consumedArgs)
566
- });
553
+ };
567
554
  this.setParsedInfo(parsedInfo, command, matchedCommandName);
568
555
  this.emit(`command:${matchedCommandName}`, command);
569
556
  break;
@@ -614,11 +601,12 @@ class CAC extends EventEmitter {
614
601
  argsAfterDoubleDashes = argv.slice(doubleDashesIndex + 1);
615
602
  argv = argv.slice(0, doubleDashesIndex);
616
603
  }
617
- let parsed = mri(argv, mriOptions);
604
+ let parsed = (0, import_mri.default)(argv, mriOptions);
618
605
  parsed = Object.keys(parsed).reduce((res, name) => {
619
- return __assign(__assign({}, res), {
606
+ return {
607
+ ...res,
620
608
  [camelcaseOptionName(name)]: parsed[name]
621
- });
609
+ };
622
610
  }, {_: []});
623
611
  const args = parsed._;
624
612
  const options = {
@@ -670,8 +658,15 @@ class CAC extends EventEmitter {
670
658
  actionArgs.push(options);
671
659
  return command.commandAction.apply(this, actionArgs);
672
660
  }
673
- }
674
-
675
- const cac = (name = "") => new CAC(name);
661
+ };
662
+ var CAC_default = CAC;
676
663
 
677
- export { CAC, Command, cac, cac as default };
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.1",
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",
@@ -31,7 +31,7 @@
31
31
  "test:cov": "jest --coverage",
32
32
  "build:deno": "node -r sucrase/register scripts/build-deno.ts",
33
33
  "build:node": "rollup -c",
34
- "build": "yarn build:deno && yarn build:node",
34
+ "build": "npm run build:deno && npm run build:node",
35
35
  "toc": "markdown-toc -i README.md",
36
36
  "prepublishOnly": "npm run build && cp mod.js mod.mjs",
37
37
  "docs:api": "typedoc --out api-doc --readme none --exclude \"**/__test__/**\" --theme minimal"