mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat:suggest matching commands if the user mistypes 🚧 (#181)
This commit is contained in:
parent
fbbbfca396
commit
9aa79485c2
2 changed files with 15 additions and 0 deletions
|
@ -45,6 +45,7 @@
|
|||
"@babel/runtime": "^7.2.0",
|
||||
"async": "^2.0.0-rc.1",
|
||||
"chalk": "^2.3.0",
|
||||
"didyoumean": "^1.2.1",
|
||||
"inquirer": "^6.2.1",
|
||||
"lodash": "^4.11.2",
|
||||
"pify": "^4.0.1",
|
||||
|
|
14
src/cli.js
14
src/cli.js
|
@ -5,6 +5,10 @@ const path = require('path')
|
|||
const yargs = require('yargs')
|
||||
const chalk = require('chalk')
|
||||
const inquirer = require('inquirer')
|
||||
const didYouMean = require('didyoumean')
|
||||
|
||||
// Setting edit length to be 60% of the input string's length
|
||||
didYouMean.threshold = 0.6
|
||||
|
||||
const init = require('./init')
|
||||
const generate = require('./generate')
|
||||
|
@ -46,6 +50,15 @@ const yargv = yargs
|
|||
}
|
||||
}).argv
|
||||
|
||||
function suggestCommands(cmd) {
|
||||
const availableCommands = ['generate', 'add', 'init', 'check']
|
||||
const suggestion = didYouMean(cmd, availableCommands)
|
||||
|
||||
if (suggestion) {
|
||||
console.log(chalk.bold(`Did you mean ${suggestion}`))
|
||||
}
|
||||
}
|
||||
|
||||
function startGeneration(argv) {
|
||||
return Promise.all(
|
||||
argv.files.map(file => {
|
||||
|
@ -170,6 +183,7 @@ promptForCommand(yargv)
|
|||
case 'check':
|
||||
return checkContributors(yargv)
|
||||
default:
|
||||
suggestCommands(command)
|
||||
throw new Error(`Unknown command ${command}`)
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue