Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ function arg(opts, {argv = process.argv.slice(2), permissive = false, stopAtPosi

if (wholeArg.length > 1 && wholeArg[0] === '-') {
/* eslint-disable operator-linebreak */
const separatedArguments = (wholeArg[1] === '-' || wholeArg.length === 2)
const separatedArguments = (wholeArg[1] === '-' || /^-.=.*$/.test(wholeArg))
? [wholeArg]
: wholeArg.slice(1).split('').map(a => `-${a}`);
/* eslint-enable operator-linebreak */

for (let j = 0; j < separatedArguments.length; j++) {
const arg = separatedArguments[j];
const [originalArgName, argStr] = arg[1] === '-' ? arg.split(/=(.*)/, 2) : [arg, undefined];
const [originalArgName, argStr] = arg.split(/=(.*)/, 2);

let argName = originalArgName;
while (argName in aliases) {
Expand Down
45 changes: 45 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,51 @@ test('should parse negative numbers (GNU equals form)', () => {
});
});

test('should parse long options (GNU equals form)', () => {
const argv = ['--option=value'];

const result = arg({
'--option': String
}, {
argv
});

expect(result).to.deep.equal({
_: [],
'--option': 'value'
});
});

test('should parse short options (GNU equals form)', () => {
const argv = ['-O=value'];

const result = arg({
'-O': String
}, {
argv
});

expect(result).to.deep.equal({
_: [],
'-O': 'value'
});
});

test('should parse negative numbers in short options options (GNU equals form)', () => {
const argv = ['-I=-15'];

const result = arg({
'-I': Number
}, {
argv
});

expect(result).to.deep.equal({
_: [],
'-I': -15
});
});

test('should parse negative numbers (separate argument form)', () => {
const argv = ['--int', '-5'];

Expand Down