Skip to content

Commit

Permalink
Use real didYouMean example for .on('command:*') (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn authored Feb 8, 2020
1 parent 1e1ed08 commit 6f3aebb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,13 @@ program.on('option:verbose', function () {
process.env.VERBOSE = this.verbose;
});

// custom error on unknown command
program.on('command:*', function (operands) {
console.error(`Invalid command '${operands[0]}'. Did you mean:`);
console.error(mySuggestions(operands[0]));
process.exit(1);
console.error(`error: unknown command '${operands[0]}'`);
const availableCommands = program.commands.map(cmd => cmd.name());
const suggestion = didYouMean(operands[0], availableCommands);
if (suggestion)
console.error(`Did you mean '${suggestion}'?`);
process.exitCode = 1;
});
```

Expand Down

0 comments on commit 6f3aebb

Please sign in to comment.