@xmorse/cac 6.0.6 → 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 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
- shouldParse = false;
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/dist/index.js CHANGED
@@ -544,8 +544,20 @@ class CAC extends events.EventEmitter {
544
544
  if (shouldParse) {
545
545
  for (const command of this.commands) {
546
546
  if (command.name === "") {
547
- shouldParse = false;
548
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;
549
561
  this.setParsedInfo(parsed, command);
550
562
  this.emit(`command:!`, command);
551
563
  }
package/dist/index.mjs CHANGED
@@ -540,8 +540,20 @@ class CAC extends EventEmitter {
540
540
  if (shouldParse) {
541
541
  for (const command of this.commands) {
542
542
  if (command.name === "") {
543
- shouldParse = false;
544
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;
545
557
  this.setParsedInfo(parsed, command);
546
558
  this.emit(`command:!`, command);
547
559
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmorse/cac",
3
- "version": "6.0.6",
3
+ "version": "6.0.7",
4
4
  "description": "Simple yet powerful framework for building command-line apps.",
5
5
  "repository": {
6
6
  "url": "egoist/cac",