Skip to content

Commit

Permalink
fix: Fix options parsing when only short name is defined (#32)
Browse files Browse the repository at this point in the history
Fix options parsing when only short name is defined
  • Loading branch information
mattallty authored Mar 14, 2017
1 parent 51139ad commit 4b5f754
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ class Command extends GetterSetter {
return this._options.reduce((acc, opt) => {
if (typeof options[opt.getLongCleanName()] !== 'undefined') {
acc[opt.name()] = options[opt.getLongCleanName()];
} else {
acc[opt.name()] = options[opt.getShortCleanName()];
}
return acc;
}, {});
Expand Down
19 changes: 19 additions & 0 deletions tests/option-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ describe('Setting up a required option (short)', () => {
});
});

describe('Setting up a just one short option', () => {

it(`should work`, () => {

const action = sinon.spy();
program
.command('foo')
.option('-t <time-in-secs>')
.action(action);

program.parse(makeArgv(['foo', '-t', '2']));
should(action.called).be.ok();
console.dir(action.args[0]);
should(action.args[0][1]).eql({t:'2'});
program.reset();
});
});


describe('Setting up a option synopsis containing an error', () => {

it(`should throw OptionSyntaxError`, () => {
Expand Down

0 comments on commit 4b5f754

Please sign in to comment.