mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-10 05:56:29 +00:00
Populate contribution choices with current values
This commit is contained in:
parent
11833b0405
commit
f9cdace376
3 changed files with 12 additions and 6 deletions
2
cli.js
2
cli.js
|
@ -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)
|
return updateContributors(argv, username, contributions, argv.contributors)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
argv.contributors = data.contributors;
|
argv.contributors = data.contributors;
|
||||||
return startGeneration(argv)
|
return startGeneration(argv)
|
||||||
|
|
|
@ -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) {
|
module.exports = function addContributor(options, username, contributions, allContributions) {
|
||||||
const answersP = prompt(options, username, contributions);
|
const answersP = prompt(options, username, contributions, allContributions);
|
||||||
const contributorsP = answersP
|
const contributorsP = answersP
|
||||||
.then(answers => add(options, answers.username, answers.contributions, github));
|
.then(answers => add(options, answers.username, answers.contributions, github));
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ var contributionChoices = _.flow(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
function getQuestions(options, username, contributions) {
|
function getQuestions(options, username, contributions, allContributions) {
|
||||||
return [{
|
return [{
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'username',
|
name: 'username',
|
||||||
|
@ -29,17 +29,23 @@ function getQuestions(options, username, contributions) {
|
||||||
name: 'contributions',
|
name: 'contributions',
|
||||||
message: 'What are the contribution types?',
|
message: 'What are the contribution types?',
|
||||||
when: !contributions,
|
when: !contributions,
|
||||||
|
default: function (answers) {
|
||||||
|
// default values for contributions when updating existing users
|
||||||
|
return allContributions
|
||||||
|
.filter((entry) => entry.login.toLowerCase() === answers.username.toLowerCase())
|
||||||
|
.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: input => input.length ? true : 'Use space to select at least one contribution type.'
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function prompt(options, username, contributions) {
|
module.exports = function prompt(options, username, contributions, allContributions) {
|
||||||
var defaults = {
|
var defaults = {
|
||||||
username: username,
|
username: username,
|
||||||
contributions: contributions && contributions.split(',')
|
contributions: contributions && contributions.split(',')
|
||||||
};
|
};
|
||||||
var questions = getQuestions(options, username, contributions);
|
var questions = getQuestions(options, username, contributions, allContributions);
|
||||||
return inquirer.prompt(questions)
|
return inquirer.prompt(questions)
|
||||||
.then(_.assign(defaults));
|
.then(_.assign(defaults));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue