Skip to content

Commit

Permalink
[Fix] Fix long option followed by single dash (#17)
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
shadowspawn authored and ljharb committed Feb 9, 2023
1 parent 72239e6 commit 63b8fee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -136,7 +136,7 @@ module.exports = function (args, opts) {
next = args[i + 1];
if (
next !== undefined
&& !(/^-/).test(next)
&& !(/^(-|--)[^-]/).test(next)
&& !flags.bools[key]
&& !flags.allBools
&& (aliases[key] ? !flags.bools[aliases[key]] : true)
Expand Down
12 changes: 11 additions & 1 deletion test/dash.js
Expand Up @@ -4,8 +4,9 @@ var parse = require('../');
var test = require('tape');

test('-', function (t) {
t.plan(5);
t.plan(6);
t.deepEqual(parse(['-n', '-']), { n: '-', _: [] });
t.deepEqual(parse(['--nnn', '-']), { nnn: '-', _: [] });
t.deepEqual(parse(['-']), { _: ['-'] });
t.deepEqual(parse(['-f-']), { f: '-', _: [] });
t.deepEqual(
Expand All @@ -31,3 +32,12 @@ test('move arguments after the -- into their own `--` array', function (t) {
{ name: 'John', _: ['before'], '--': ['after'] }
);
});

test('--- option value', function (t) {
// A multi-dash value is largely an edge case, but check the behaviour is as expected,
// and in particular the same for short option and long option (as made consistent in Jan 2023).
t.plan(2);
t.deepEqual(parse(['-n', '---']), { n: '---', _: [] });
t.deepEqual(parse(['--nnn', '---']), { nnn: '---', _: [] });
});

0 comments on commit 63b8fee

Please sign in to comment.