Skip to content
Myr

Assume a string parameter to implies is name of boolean option. (#1854)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent 869c3c0 · Browse files · 3 files+17 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+17 added−2 removed

  • tests:+11 added−0 removed
  • other:+6 added−2 removed

3 files+17 added−2 removed

modified:examples/options-implies.js-1 removed
modified:lib/option.js+6 added-1 removed
97 unmodified lines
98 * @param {Object} impliedOptionValues99 * @return {Option}100 */101 implies(impliedOptionValues) {102 let newImplied = impliedOptionValues;103 if (typeof impliedOptionValues === 'string') {104 // string is not documented, but easy mistake and we can do what user probably intended.105 newImplied = { [impliedOptionValues]: true };106 }102 this.implied = Object.assign(this.implied || {}, impliedOptionValues);107 this.implied = Object.assign(this.implied || {}, newImplied);108 return this;109 }110111 /**
220 unmodified lines
modified:tests/options.implies.test.js+11 added
199 unmodified lines
200 program.parse(['--foo'], { from: 'user' });201 expect(program.opts().bar).toEqual(true);202 expect(called).toEqual(false);203});204205test('when passed string then treat as boolean', () => {206 // Do something sensible instead of something silly if user passes just name of option.207 // https://github.com/tj/commander.js/issues/1852208 const program = new Command();209 program210 .addOption(new Option('--foo').implies('bar'))211 .option('-b, --bar', 'description');212 program.parse(['--foo'], { from: 'user' });213 expect(program.opts().bar).toEqual(true);214});