From e94a45851dcfa08d5ce92b6f17cd868acae94ee4 Mon Sep 17 00:00:00 2001 From: Gar Date: Fri, 19 Mar 2021 07:33:40 -0700 Subject: fix(suggestions): clarify Unknown command output Base commands and `npm run` need different outputs PR-URL: https://github.com/npm/cli/pull/2906 Credit: @wraithgar Close: #2906 Reviewed-by: @ruyadorno --- lib/utils/did-you-mean.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'lib/utils') diff --git a/lib/utils/did-you-mean.js b/lib/utils/did-you-mean.js index 5e41af67a..98133196e 100644 --- a/lib/utils/did-you-mean.js +++ b/lib/utils/did-you-mean.js @@ -23,10 +23,11 @@ const didYouMean = async (npm, path, scmd) => { const best = [...bestCmd, ...bestRun, ...bestBin] - const suggestion = best.length === 0 ? '' - : best.length === 1 ? `\n\nDid you mean this?\n${best[0]}` + if (best.length === 0) + return '' + + const suggestion = best.length === 1 ? `\n\nDid you mean this?\n${best[0]}` : `\n\nDid you mean one of these?\n${best.slice(0, 3).join('\n')}` - const result = `Unknown command: "${scmd}"${suggestion}` - return result + return suggestion } module.exports = didYouMean -- cgit v1.2.3