Skip to content

Commit

Permalink
fix: allow boolean option to be set in config file
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Feb 16, 2018
1 parent 4d04901 commit 857d418
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cli.js
Expand Up @@ -20,23 +20,25 @@ Usage:
.option('r', {alias: 'repository-url', describe: 'Git repository URL', type: 'string', group: 'Options'})
.option('t', {alias: 'tag-format', describe: 'Git tag format', type: 'string', group: 'Options'})
.option('e', {alias: 'extends', describe: 'Shareable configurations', ...stringList, group: 'Options'})
.option('ci', {describe: 'Toggle CI verifications', default: true, type: 'boolean', group: 'Options'})
.option('ci', {describe: 'Toggle CI verifications', default: undefined, type: 'boolean', group: 'Options'})
.option('verify-conditions', {...stringList, group: 'Plugins'})
.option('analyze-commits', {type: 'string', group: 'Plugins'})
.option('verify-release', {...stringList, group: 'Plugins'})
.option('generate-notes', {type: 'string', group: 'Plugins'})
.option('publish', {...stringList, group: 'Plugins'})
.option('success', {...stringList, group: 'Plugins'})
.option('fail', {...stringList, group: 'Plugins'})
.option('debug', {describe: 'Output debugging information', default: false, type: 'boolean', group: 'Options'})
.option('d', {alias: 'dry-run', describe: 'Skip publishing', default: false, type: 'boolean', group: 'Options'})
.option('h', {alias: 'help', group: 'Options'})
.option('v', {alias: 'version', group: 'Options'})
.option('debug', {describe: 'Output debugging information', default: undefined, type: 'boolean', group: 'Options'})
.option('d', {alias: 'dry-run', describe: 'Skip publishing', default: undefined, type: 'boolean', group: 'Options'})
.option('h', {alias: 'help', default: undefined, group: 'Options'})
.option('v', {alias: 'version', default: undefined, group: 'Options'})
.strict(false)
.exitProcess(false);

try {
const {help, version, ...opts} = cli.argv;
// Remove option with undefined values, as yargs sets non defined options as `undefined`
const {help, version, ...opts} = pickBy(cli.argv, value => !isUndefined(value));

if (Boolean(help) || Boolean(version)) {
process.exitCode = 0;
return;
Expand All @@ -52,8 +54,7 @@ Usage:
require('debug').enable('semantic-release:*');
}

// Remove option with undefined values, as yargs sets non defined options as `undefined`
await require('.')(pickBy(opts, value => !isUndefined(value)));
await require('.')(opts);
process.exitCode = 0;
} catch (err) {
if (err.name !== 'YError') {
Expand Down
16 changes: 16 additions & 0 deletions test/cli.test.js
Expand Up @@ -153,6 +153,22 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa
t.is(process.exitCode, 0);
});

test.serial('Do not set properties in option for which arg is not in command line', async t => {
const run = stub().resolves(true);
const cli = proxyquire('../cli', {'.': run});

process.argv = ['', '', '-b', 'master'];

await cli();

t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 'ci'));
t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 'd'));
t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 'dry-run'));
t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 'debug'));
t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 'r'));
t.false(Object.prototype.hasOwnProperty.call(run.args[0][0], 't'));
});

test.serial('Set "noCi" options to "true" with "--no-ci"', async t => {
const run = stub().resolves(true);
const cli = proxyquire('../cli', {'.': run});
Expand Down

0 comments on commit 857d418

Please sign in to comment.