yargs 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/minimist.js CHANGED
@@ -57,8 +57,12 @@ module.exports = function (args, opts) {
57
57
  Object.keys(defaults || {}).forEach(function (key) {
58
58
  if (/-/.test(key) && !opts.alias[key]) {
59
59
  var c = toCamelCase(key);
60
- aliases[key] = (aliases[key] || []).concat(c);
61
- newAliases[c] = true;
60
+ aliases[key] = aliases[key] || [];
61
+ // don't allow the same key to be added multiple times.
62
+ if (aliases[key].indexOf(c) === -1) {
63
+ aliases[key] = (aliases[key] || []).concat(c);
64
+ newAliases[c] = true;
65
+ }
62
66
  }
63
67
  (aliases[key] || []).forEach(function (alias) {
64
68
  defaults[alias] = defaults[key];
@@ -71,7 +75,6 @@ module.exports = function (args, opts) {
71
75
  });
72
76
 
73
77
  var notFlags = [];
74
-
75
78
  if (args.indexOf('--') !== -1) {
76
79
  notFlags = args.slice(args.indexOf('--')+1);
77
80
  args = args.slice(0, args.indexOf('--'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Light-weight option parsing with an argv hash. No optstrings attached.",
5
5
  "main": "./index.js",
6
6
  "dependencies": {},
package/test/parse.js CHANGED
@@ -15,7 +15,7 @@ describe('parse', function () {
15
15
  parse.should.have.property('bool', true);
16
16
  parse.should.have.property('_').with.length(0);
17
17
  });
18
-
18
+
19
19
  it('should place bare options in the _ array', function () {
20
20
  var parse = yargs.parse(['foo', 'bar', 'baz']);
21
21
  parse.should.have.property('_').and.deep.equal(['foo','bar','baz']);
@@ -38,7 +38,7 @@ describe('parse', function () {
38
38
  parse.should.have.property('s', 'meow');
39
39
  parse.should.have.property('_').with.length(0);
40
40
  });
41
-
41
+
42
42
  it('should set the value of a single short option to the next supplied value', function () {
43
43
  var parse = yargs.parse(['-h', 'localhost']);
44
44
  parse.should.have.property('h', 'localhost');
@@ -85,7 +85,7 @@ describe('parse', function () {
85
85
  parse.should.have.property('h', 'localhost');
86
86
  parse.should.have.property('_').and.deep.equal(['script.js']);
87
87
  });
88
-
88
+
89
89
  it('should still set values appropriately if a mix of short and long options are specified', function () {
90
90
  var parse = yargs.parse(['-h', 'localhost', '--port', '555']);
91
91
  parse.should.have.property('h', 'localhost');
@@ -98,13 +98,13 @@ describe('parse', function () {
98
98
  parse.should.have.property('moo', false);
99
99
  parse.should.have.property('_').with.length(0);
100
100
  });
101
-
101
+
102
102
  it('should group values into an array if the same option is specified multiple times', function () {
103
103
  var parse = yargs.parse(['-v', 'a', '-v', 'b', '-v', 'c' ]);
104
104
  parse.should.have.property('v').and.deep.equal(['a','b','c']);
105
105
  parse.should.have.property('_').with.length(0);
106
106
  });
107
-
107
+
108
108
  it('should still set values appropriately if we supply a comprehensive list of various types of options', function () {
109
109
  var parse = yargs.parse([
110
110
  '--name=meowmers', 'bare', '-cats', 'woo',
@@ -352,4 +352,38 @@ describe('parse', function () {
352
352
  parsed.should.have.property('other', 'false');
353
353
  });
354
354
 
355
+ // regression, see https://github.com/chevex/yargs/issues/63
356
+ it('should not add the same key to argv multiple times, when creating camel-case aliases', function() {
357
+ var yargs = require('../')(['--health-check=banana', '--second-key', 'apple', '-t=blarg'])
358
+ .options('h', {
359
+ alias: 'health-check',
360
+ description: 'health check',
361
+ default: 'apple'
362
+ })
363
+ .options('second-key', {
364
+ alias: 's',
365
+ description: 'second key',
366
+ default: 'banana'
367
+ })
368
+ .options('third-key', {
369
+ alias: 't',
370
+ description: 'third key',
371
+ default: 'third'
372
+ })
373
+
374
+ // before this fix, yargs failed parsing
375
+ // one but not all forms of an arg.
376
+ yargs.argv.secondKey.should.eql('apple');
377
+ yargs.argv.s.should.eql('apple');
378
+ yargs.argv['second-key'].should.eql('apple');
379
+
380
+ yargs.argv.healthCheck.should.eql('banana');
381
+ yargs.argv.h.should.eql('banana');
382
+ yargs.argv['health-check'].should.eql('banana');
383
+
384
+ yargs.argv.thirdKey.should.eql('blarg');
385
+ yargs.argv.t.should.eql('blarg');
386
+ yargs.argv['third-key'].should.eql('blarg');
387
+ });
388
+
355
389
  });