Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Fix for issue #394, Compound short options and operands are conflated
Browse files Browse the repository at this point in the history
  • Loading branch information
dkl-ppi committed Mar 24, 2014
1 parent 5d15e17 commit bba3e4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function shortOptionExtra(options, arg) {
if (!opt) { throw new Error("Unknown option '" + arg + "'"); }
var flag = arg.slice(0, 2);
var extra = arg.slice(2);
if (opt.hasValue) {return [flag, extra]; }
if (opt.hasValue && extra) { return [flag, extra]; }
if (!extra) { return [flag]; }
return [flag].concat(shortOptionExtra(options, "-" + extra));
}
Expand Down Expand Up @@ -142,6 +142,7 @@ function parse(options, args, done) {
}

args = tokenize(args, options);

var nextArg, operandMode = false;

while (args.length > 0) {
Expand Down
13 changes: 13 additions & 0 deletions test/posix-argv-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,18 @@ buster.testCase("posix-argv-parser", {
this.a.parse(["-node"], done(function (errors, options) {
assert.match(errors[0], "Unknown option '-node'");
}));
},

"does not use option value as operand": function (done) {
this.a.createOption(['--config', '-c'], {hasValue: false});
this.a.createOption(['--length', '-l'], {hasValue: true});
this.a.createOperand('service');

this.a.parse(['-cl', '10'], done(function (error, options) {
assert.isTrue(options["-c"].isSet);
assert.isTrue(options["-l"].isSet);
assert.equals(options["-l"].value, "10");
assert.isFalse(options.service.isSet);
}));
}
});

0 comments on commit bba3e4c

Please sign in to comment.