mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 05:56:29 +00:00
Add prompt/auto-init when no arguments are given (fixes #10)
This commit is contained in:
parent
ea9badba3e
commit
f5f5ee0709
1 changed files with 33 additions and 7 deletions
40
cli.js
40
cli.js
|
@ -5,6 +5,7 @@
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var yargs = require('yargs');
|
var yargs = require('yargs');
|
||||||
|
var inquirer = require('inquirer');
|
||||||
|
|
||||||
var init = require('./lib/init');
|
var init = require('./lib/init');
|
||||||
var generate = require('./lib/generate');
|
var generate = require('./lib/generate');
|
||||||
|
@ -83,12 +84,37 @@ function onError(error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var command = argv._[0];
|
function promptForCommand(argv, cb) {
|
||||||
|
try {
|
||||||
|
fs.statSync(argv.config);
|
||||||
|
} catch (error) { // No config file --> first time using the command
|
||||||
|
return cb('init');
|
||||||
|
}
|
||||||
|
|
||||||
if (command === 'init') {
|
var questions = [{
|
||||||
init(onError);
|
type: 'list',
|
||||||
} else if (command === 'generate') {
|
name: 'command',
|
||||||
startGeneration(argv, onError);
|
message: "What do you want to do?",
|
||||||
} else if (command === 'add') {
|
choices: [{
|
||||||
addContribution(argv, onError);
|
name: 'Add a new contributor or add a new contribution type',
|
||||||
|
value: 'add'
|
||||||
|
}, {
|
||||||
|
name: 'Re-generate the contributors list',
|
||||||
|
value: 'generate'
|
||||||
|
}],
|
||||||
|
default: 0
|
||||||
|
}];
|
||||||
|
inquirer.prompt(questions, function treatAnswers(answers) {
|
||||||
|
return cb(answers.command);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
promptForCommand(argv, function (command) {
|
||||||
|
if (command === 'init') {
|
||||||
|
init(onError);
|
||||||
|
} else if (command === 'generate') {
|
||||||
|
startGeneration(argv, onError);
|
||||||
|
} else if (command === 'add') {
|
||||||
|
addContribution(argv, onError);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue