mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-03 02:53:40 +00:00
00d6249711
Now generates CLI, env and docs Makes config more testable
69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
const clearRequire = require('clear-require');
|
|
let commander = require('commander');
|
|
const configDefinitions = require('./definitions');
|
|
|
|
module.exports = {
|
|
getCliName,
|
|
getConfig,
|
|
};
|
|
|
|
function getCliName(option) {
|
|
if (option.cli === false) {
|
|
return '';
|
|
}
|
|
const nameWithHyphens = option.name.replace(/([A-Z])/g, '-$1');
|
|
return `--${nameWithHyphens.toLowerCase()}`;
|
|
}
|
|
|
|
function getConfig(argv) {
|
|
clearRequire('commander');
|
|
commander = require('commander'); // eslint-disable-line
|
|
const options = configDefinitions.getOptions();
|
|
|
|
const config = {};
|
|
|
|
const coersions = {
|
|
boolean: val => (val === 'true'),
|
|
list: val => val.split(',').map(el => el.trim()),
|
|
string: val => val,
|
|
};
|
|
|
|
let program = commander.arguments('[repositories...]');
|
|
|
|
options.forEach((option) => {
|
|
if (option.cli !== false) {
|
|
const param = `<${option.type}>`.replace('<boolean>', '[boolean]');
|
|
const optionString = `${getCliName(option)} ${param}`;
|
|
program = program.option(optionString, option.description, coersions[option.type]);
|
|
}
|
|
});
|
|
|
|
/* istanbul ignore next */
|
|
function helpConsole() {
|
|
/* eslint-disable no-console */
|
|
console.log(' Examples:');
|
|
console.log('');
|
|
console.log(' $ renovate --token abc123 singapore/lint-condo');
|
|
console.log(' $ renovate --ignore-unstable=false --log-level verbose singapore/lint-condo');
|
|
console.log(' $ renovate singapore/lint-condo singapore/package-test');
|
|
/* eslint-enable no-console */
|
|
}
|
|
|
|
program = program
|
|
.on('--help', helpConsole)
|
|
.action((repositories) => {
|
|
config.repositories = repositories;
|
|
})
|
|
.parse(argv);
|
|
|
|
options.forEach((option) => {
|
|
if (option.cli !== false) {
|
|
if (program[option.name] !== undefined) {
|
|
config[option.name] = program[option.name];
|
|
}
|
|
}
|
|
});
|
|
|
|
return config;
|
|
}
|