Skip to content

Commit 6f3aebb

Browse files
authored
Use real didYouMean example for .on('command:*') (#1176)
1 parent 1e1ed08 commit 6f3aebb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Readme.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,13 @@ program.on('option:verbose', function () {
554554
process.env.VERBOSE = this.verbose;
555555
});
556556
557-
// custom error on unknown command
558557
program.on('command:*', function (operands) {
559-
console.error(`Invalid command '${operands[0]}'. Did you mean:`);
560-
console.error(mySuggestions(operands[0]));
561-
process.exit(1);
558+
console.error(`error: unknown command '${operands[0]}'`);
559+
const availableCommands = program.commands.map(cmd => cmd.name());
560+
const suggestion = didYouMean(operands[0], availableCommands);
561+
if (suggestion)
562+
console.error(`Did you mean '${suggestion}'?`);
563+
process.exitCode = 1;
562564
});
563565
```
564566

0 commit comments

Comments
 (0)