Fix error with add from cli, remove unneeded param

This commit is contained in:
Chris Vickery 2017-11-07 09:06:54 -08:00
parent f9cdace376
commit 48b0ed4b8e
3 changed files with 21 additions and 8 deletions

2
cli.js
View file

@ -56,7 +56,7 @@ function addContribution(argv) {
var username = argv._[1]; var username = argv._[1];
var contributions = argv._[2]; var contributions = argv._[2];
// Add or update contributor in the config file // Add or update contributor in the config file
return updateContributors(argv, username, contributions, argv.contributors) return updateContributors(argv, username, contributions)
.then(data => { .then(data => {
argv.contributors = data.contributors; argv.contributors = data.contributors;
return startGeneration(argv) return startGeneration(argv)

View file

@ -10,8 +10,8 @@ function isNewContributor(contributorList, username) {
return !_.find({login: username}, contributorList); return !_.find({login: username}, contributorList);
} }
module.exports = function addContributor(options, username, contributions, allContributions) { module.exports = function addContributor(options, username, contributions) {
const answersP = prompt(options, username, contributions, allContributions); const answersP = prompt(options, username, contributions);
const contributorsP = answersP const contributorsP = answersP
.then(answers => add(options, answers.username, answers.contributions, github)); .then(answers => add(options, answers.username, answers.contributions, github));

View file

@ -18,7 +18,7 @@ var contributionChoices = _.flow(
}) })
); );
function getQuestions(options, username, contributions, allContributions) { function getQuestions(options, username, contributions) {
return [{ return [{
type: 'input', type: 'input',
name: 'username', name: 'username',
@ -31,21 +31,34 @@ function getQuestions(options, username, contributions, allContributions) {
when: !contributions, when: !contributions,
default: function (answers) { default: function (answers) {
// default values for contributions when updating existing users // default values for contributions when updating existing users
return allContributions answers.username = answers.username || username;
return options.contributors
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase()) .filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
.reduce((memo, entry) => memo.concat(entry.contributions), []); .reduce((memo, entry) => memo.concat(entry.contributions), []);
}, },
choices: contributionChoices(options), choices: contributionChoices(options),
validate: input => input.length ? true : 'Use space to select at least one contribution type.' validate: function (input, answers) {
answers.username = answers.username || username;
var previousContributions = options.contributors
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
.reduce((memo, entry) => memo.concat(entry.contributions), []);
if (!input.length) {
return 'Use space to select at least one contribution type.'
} else if (_.isEqual(input, previousContributions)) {
return 'Nothing changed, use space to select contribution types.'
}
return true;
}
}]; }];
} }
module.exports = function prompt(options, username, contributions, allContributions) { module.exports = function prompt(options, username, contributions) {
var defaults = { var defaults = {
username: username, username: username,
contributions: contributions && contributions.split(',') contributions: contributions && contributions.split(',')
}; };
var questions = getQuestions(options, username, contributions, allContributions); var questions = getQuestions(options, username, contributions);
return inquirer.prompt(questions) return inquirer.prompt(questions)
.then(_.assign(defaults)); .then(_.assign(defaults));
}; };