mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 21:46:29 +00:00
chore: make use of inhouse command recommendation (#228)
This commit is contained in:
parent
ed9d84d5d8
commit
7d83c7cac1
2 changed files with 1 additions and 15 deletions
|
@ -45,7 +45,6 @@
|
||||||
"@babel/runtime": "^7.2.0",
|
"@babel/runtime": "^7.2.0",
|
||||||
"async": "^3.0.1",
|
"async": "^3.0.1",
|
||||||
"chalk": "^3.0.0",
|
"chalk": "^3.0.0",
|
||||||
"didyoumean": "^1.2.1",
|
|
||||||
"inquirer": "^6.2.1",
|
"inquirer": "^6.2.1",
|
||||||
"json-fixer": "^1.3.1-0",
|
"json-fixer": "^1.3.1-0",
|
||||||
"lodash": "^4.11.2",
|
"lodash": "^4.11.2",
|
||||||
|
|
15
src/cli.js
15
src/cli.js
|
@ -5,10 +5,6 @@ const path = require('path')
|
||||||
const yargs = require('yargs')
|
const yargs = require('yargs')
|
||||||
const chalk = require('chalk')
|
const chalk = require('chalk')
|
||||||
const inquirer = require('inquirer')
|
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 init = require('./init')
|
||||||
const generate = require('./generate')
|
const generate = require('./generate')
|
||||||
|
@ -24,6 +20,7 @@ const yargv = yargs
|
||||||
.alias('h', 'help')
|
.alias('h', 'help')
|
||||||
.alias('v', 'version')
|
.alias('v', 'version')
|
||||||
.version()
|
.version()
|
||||||
|
.recommendCommands()
|
||||||
.command('generate', 'Generate the list of contributors')
|
.command('generate', 'Generate the list of contributors')
|
||||||
.usage('Usage: $0 generate')
|
.usage('Usage: $0 generate')
|
||||||
.command('add', 'add a new contributor')
|
.command('add', 'add a new contributor')
|
||||||
|
@ -50,15 +47,6 @@ const yargv = yargs
|
||||||
}
|
}
|
||||||
}).argv
|
}).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) {
|
function startGeneration(argv) {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
argv.files.map(file => {
|
argv.files.map(file => {
|
||||||
|
@ -183,7 +171,6 @@ promptForCommand(yargv)
|
||||||
case 'check':
|
case 'check':
|
||||||
return checkContributors(yargv)
|
return checkContributors(yargv)
|
||||||
default:
|
default:
|
||||||
suggestCommands(command)
|
|
||||||
throw new Error(`Unknown command ${command}`)
|
throw new Error(`Unknown command ${command}`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue