Skip to content

Commit

Permalink
For "--some-option", also set argv.someOption
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen committed Feb 16, 2014
1 parent f2376af commit 56e6528
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/minimist.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ module.exports = function (args, opts) {
var aliases = {};
Object.keys(opts.alias || {}).forEach(function (key) {
aliases[key] = [].concat(opts.alias[key]);
// For "--option-name", also set argv.optionName
aliases[key].concat(key).forEach(function (x) {
if (/-/.test(x)) {
aliases[key].push(
x.split('-').map(function(word, i) {
return (i ? word[0].toUpperCase() + word.slice(1) : word);
}).join(''));
}
});
aliases[key].forEach(function (x) {
aliases[x] = [key].concat(aliases[key].filter(function (y) {
return x !== y;
Expand Down
31 changes: 31 additions & 0 deletions test/parse_camelCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var should = require('chai').should(),
yargs = require('../');

describe('parse', function () {

describe('dashes and camelCase', function () {

it('should provide options with dashes as camelCase properties', function () {
var result = yargs()
.option('some-option', {
alias : 'o',
describe : 'some option'
})
.parse([ '--some-option' ]);

result.should.have.property('someOption').that.is.a('boolean').and.is.true;
});

it('should provide aliases with dashes as camelCase properties', function() {
var result = yargs()
.option('o', {
alias : 'some-option',
describe : 'some option'
})
.parse([ '--some-option', 'val' ]);

result.should.have.property('someOption').that.is.a('string').and.equals('val');
});
});

});

0 comments on commit 56e6528

Please sign in to comment.