From 256fa145ad7b07eb7a60c398a3bb904daafe0593 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sat, 8 Feb 2020 10:59:19 +1300 Subject: [PATCH] Use real didYouMean example for .on('command:*') --- Readme.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Readme.md b/Readme.md index b8d20dfa1..03ec1498c 100644 --- a/Readme.md +++ b/Readme.md @@ -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; }); ```