Skip to content

Commit f711709

Browse files
author
Vitaly Puzrin
committedOct 27, 2015
Merge pull request #84 from CatWithApple/master
fix: use '=' in args
2 parents 19496d1 + c2f6b45 commit f711709

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed
 

‎lib/argument_parser.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,8 @@ ArgumentParser.prototype._parseOptional = function (argString) {
741741

742742
// if the option string before the "=" is present, return the action
743743
if (argString.indexOf('=') >= 0) {
744-
var argStringSplit = argString.split('=');
745-
optionString = argStringSplit[0];
746-
argExplicit = argStringSplit[1];
744+
optionString = argString.split('=', 1)[0];
745+
argExplicit = argString.slice(optionString.length + 1);
747746

748747
if (!!this._optionStringActions[optionString]) {
749748
action = this._optionStringActions[optionString];

‎test/base.js

+10
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,16 @@ describe('base', function () {
123123
args = parser.parseArgs(['-1']);
124124
assert.equal(args.bar, -1);
125125
});
126+
127+
it("should parse arguments with '='", function () {
128+
parser = new ArgumentParser({debug: true});
129+
parser.addArgument(['-f', '--foo']);
130+
parser.addArgument([ 'bar' ]);
131+
132+
args = parser.parseArgs('-f="foo=nice=path" "bar=nice=path"'.split(' '));
133+
assert.equal(args.foo, '"foo=nice=path"');
134+
assert.equal(args.bar, '"bar=nice=path"');
135+
});
126136

127137
it("No negative number options; neg number is positional argument", function () {
128138
parser = new ArgumentParser({debug: true});

0 commit comments

Comments
 (0)
Please sign in to comment.