Skip to content
Myr

#395 fix, short options do not understand adjacent values

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

authored by TheRoSS · committed by TheRoSS · parent 89858e5 · Browse files · 2 files+34 added−6 removed
This commit

State

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

Diff stats

2 files+34 added−6 removed

  • tests:+18 added−0 removed
  • other:+16 added−6 removed

2 files+34 added−6 removed

added:test/test.options.short.adjacent-value.js+18 added
modified:index.js+16 added-6 removed
450 unmodified lines
451 argv.push('--help');452 }453454 // process argv455 var parsed = this.parseOptions(this.normalize(argv.slice(2)));455 var normalized = this.normalize(argv.slice(2));456 var parsed = this.parseOptions(normalized);457 var args = this.args = parsed.args;458459 var result = this.parseArgs(this.args, parsed.unknown);460
118 unmodified lines
579Command.prototype.normalize = function(args) {580 var ret = []581 , arg582 , lastOpt582 , index;583 , index584 ,short585 ,opt;586587 for (var i = 0, len = args.length; i < len; ++i) {588 arg = args[i];589 if (i > 0) {
5 unmodified lines
595 ret = ret.concat(args.slice(i));596 break;597 } else if (lastOpt && lastOpt.required) {598 ret.push(arg);599 } else if (arg.length > 2 && '-' == arg[0] && '-' != arg[1]) {600 short = arg.slice(0, 2);601 opt = this.optionFor(short);602 if (opt && (opt.required || opt.optional)) {603 ret.push(short);604 ret.push(arg.slice(2));596 } else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {597 arg.slice(1).split('').forEach(function(c) {598 ret.push('-' + c);599 });605 } else {606 arg.slice(1).split('').forEach(function (c) {607 ret.push('-' + c);608 });609 }610 } else if (/^--/.test(arg) && ~(index = arg.indexOf('='))) {611 ret.push(arg.slice(0, index), arg.slice(index + 1));612 } else {613 ret.push(arg);
526 unmodified lines