diff --git a/cli.js b/cli.js index b1f1c715..7fe2a8cb 100755 --- a/cli.js +++ b/cli.js @@ -20,7 +20,7 @@ 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'}) @@ -28,15 +28,17 @@ Usage: .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; @@ -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') { diff --git a/test/cli.test.js b/test/cli.test.js index fcb1d166..fd057e49 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -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});