all-contributors-cli/lib/contributors/prompt.js
Mehdi Achour de043e0bbf fix: make selecting at least one contribution type mandatory (#56)
* Add @machour as a contributor

* fix: make selecting at least one contribution type mandatory
2017-11-02 10:53:55 -06:00

45 lines
1.1 KiB
JavaScript

'use strict';
var _ = require('lodash/fp');
var inquirer = require('inquirer');
var util = require('../util');
var contributionChoices = _.flow(
util.contributionTypes,
_.toPairs,
_.sortBy(function (pair) {
return pair[1].description;
}),
_.map(function (pair) {
return {
name: pair[1].symbol + ' ' + pair[1].description,
value: pair[0]
};
})
);
function getQuestions(options, username, contributions) {
return [{
type: 'input',
name: 'username',
message: 'What is the contributor\'s GitHub username?',
when: !username
}, {
type: 'checkbox',
name: 'contributions',
message: 'What are the contribution types?',
when: !contributions,
choices: contributionChoices(options),
validate: input => input.length ? true : 'Use space to select at least one contribution type.'
}];
}
module.exports = function prompt(options, username, contributions) {
var defaults = {
username: username,
contributions: contributions && contributions.split(',')
};
var questions = getQuestions(options, username, contributions);
return inquirer.prompt(questions)
.then(_.assign(defaults));
};