mirror of
https://github.com/nodejs/node.git
synced 2025-05-16 03:17:26 +00:00

Closes: https://github.com/nodejs/node/pull/16280 PR-URL: https://github.com/nodejs/node/pull/16509 Fixes: https://github.com/nodejs/node/issues/14161 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
21 lines
495 B
JavaScript
21 lines
495 B
JavaScript
var meant = require('meant')
|
|
var output = require('./output.js')
|
|
|
|
function didYouMean (scmd, commands) {
|
|
var bestSimilarity = meant(scmd, commands).map(function (str) {
|
|
return ' ' + str
|
|
})
|
|
|
|
if (bestSimilarity.length === 0) return
|
|
if (bestSimilarity.length === 1) {
|
|
output('\nDid you mean this?\n' + bestSimilarity[0])
|
|
} else {
|
|
output(
|
|
['\nDid you mean one of these?']
|
|
.concat(bestSimilarity.slice(0, 3)).join('\n')
|
|
)
|
|
}
|
|
}
|
|
|
|
module.exports = didYouMean
|