@xmorse/cac 6.0.5 → 6.0.7
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 +15 -1
- package/deno/Command.ts +3 -5
- package/dist/index.js +15 -9
- package/dist/index.mjs +15 -9
- package/package.json +1 -1
package/deno/CAC.ts
CHANGED
|
@@ -187,8 +187,22 @@ class CAC extends EventEmitter {
|
|
|
187
187
|
// Search the default command
|
|
188
188
|
for (const command of this.commands) {
|
|
189
189
|
if (command.name === '') {
|
|
190
|
-
|
|
190
|
+
// Check if any argument is a prefix of an existing command
|
|
191
|
+
// If so, don't match the default command (user probably mistyped a subcommand)
|
|
191
192
|
const parsed = this.mri(argv.slice(2), command);
|
|
193
|
+
const firstArg = parsed.args[0];
|
|
194
|
+
if (firstArg) {
|
|
195
|
+
const isPrefixOfCommand = this.commands.some(cmd => {
|
|
196
|
+
if (cmd.name === '') return false;
|
|
197
|
+
const cmdParts = cmd.name.split(' ');
|
|
198
|
+
return cmdParts[0] === firstArg;
|
|
199
|
+
});
|
|
200
|
+
if (isPrefixOfCommand) {
|
|
201
|
+
// Don't match default command - let it fall through to "unknown command"
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
shouldParse = false;
|
|
192
206
|
this.setParsedInfo(parsed, command);
|
|
193
207
|
this.emit(`command:!`, command);
|
|
194
208
|
}
|
package/deno/Command.ts
CHANGED
|
@@ -150,11 +150,9 @@ class Command {
|
|
|
150
150
|
sections.push({
|
|
151
151
|
title: 'Commands',
|
|
152
152
|
body: commands.map(command => {
|
|
153
|
-
|
|
154
|
-
const firstLine =
|
|
155
|
-
|
|
156
|
-
const padding = ' ' + ' '.repeat(longestCommandName.length) + ' ';
|
|
157
|
-
return [` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`, ...restLines.map(line => `${padding} ${line}`)].join('\n');
|
|
153
|
+
// Only show first line of description in commands listing
|
|
154
|
+
const firstLine = command.description.split('\n')[0].trim();
|
|
155
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
158
156
|
}).join('\n')
|
|
159
157
|
});
|
|
160
158
|
sections.push({
|
package/dist/index.js
CHANGED
|
@@ -358,14 +358,8 @@ class Command {
|
|
|
358
358
|
sections.push({
|
|
359
359
|
title: "Commands",
|
|
360
360
|
body: commands.map((command) => {
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
const restLines = descLines.slice(1);
|
|
364
|
-
const padding = " " + " ".repeat(longestCommandName.length) + " ";
|
|
365
|
-
return [
|
|
366
|
-
` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`,
|
|
367
|
-
...restLines.map((line) => `${padding} ${line}`)
|
|
368
|
-
].join("\n");
|
|
361
|
+
const firstLine = command.description.split("\n")[0].trim();
|
|
362
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
369
363
|
}).join("\n")
|
|
370
364
|
});
|
|
371
365
|
sections.push({
|
|
@@ -550,8 +544,20 @@ class CAC extends events.EventEmitter {
|
|
|
550
544
|
if (shouldParse) {
|
|
551
545
|
for (const command of this.commands) {
|
|
552
546
|
if (command.name === "") {
|
|
553
|
-
shouldParse = false;
|
|
554
547
|
const parsed = this.mri(argv.slice(2), command);
|
|
548
|
+
const firstArg = parsed.args[0];
|
|
549
|
+
if (firstArg) {
|
|
550
|
+
const isPrefixOfCommand = this.commands.some((cmd) => {
|
|
551
|
+
if (cmd.name === "")
|
|
552
|
+
return false;
|
|
553
|
+
const cmdParts = cmd.name.split(" ");
|
|
554
|
+
return cmdParts[0] === firstArg;
|
|
555
|
+
});
|
|
556
|
+
if (isPrefixOfCommand) {
|
|
557
|
+
continue;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
shouldParse = false;
|
|
555
561
|
this.setParsedInfo(parsed, command);
|
|
556
562
|
this.emit(`command:!`, command);
|
|
557
563
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -354,14 +354,8 @@ class Command {
|
|
|
354
354
|
sections.push({
|
|
355
355
|
title: "Commands",
|
|
356
356
|
body: commands.map((command) => {
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
const restLines = descLines.slice(1);
|
|
360
|
-
const padding = " " + " ".repeat(longestCommandName.length) + " ";
|
|
361
|
-
return [
|
|
362
|
-
` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`,
|
|
363
|
-
...restLines.map((line) => `${padding} ${line}`)
|
|
364
|
-
].join("\n");
|
|
357
|
+
const firstLine = command.description.split("\n")[0].trim();
|
|
358
|
+
return ` ${padRight(command.rawName, longestCommandName.length)} ${firstLine}`;
|
|
365
359
|
}).join("\n")
|
|
366
360
|
});
|
|
367
361
|
sections.push({
|
|
@@ -546,8 +540,20 @@ class CAC extends EventEmitter {
|
|
|
546
540
|
if (shouldParse) {
|
|
547
541
|
for (const command of this.commands) {
|
|
548
542
|
if (command.name === "") {
|
|
549
|
-
shouldParse = false;
|
|
550
543
|
const parsed = this.mri(argv.slice(2), command);
|
|
544
|
+
const firstArg = parsed.args[0];
|
|
545
|
+
if (firstArg) {
|
|
546
|
+
const isPrefixOfCommand = this.commands.some((cmd) => {
|
|
547
|
+
if (cmd.name === "")
|
|
548
|
+
return false;
|
|
549
|
+
const cmdParts = cmd.name.split(" ");
|
|
550
|
+
return cmdParts[0] === firstArg;
|
|
551
|
+
});
|
|
552
|
+
if (isPrefixOfCommand) {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
shouldParse = false;
|
|
551
557
|
this.setParsedInfo(parsed, command);
|
|
552
558
|
this.emit(`command:!`, command);
|
|
553
559
|
}
|