Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix long option followed by single dash #17

Merged
merged 1 commit into from
Feb 9, 2023
Merged
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
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ module.exports = function (args, opts) {
next = args[i + 1];
if (
next !== undefined
&& !(/^-/).test(next)
&& !(/^(-|--)[^-]/).test(next)
shadowspawn marked this conversation as resolved.
Show resolved Hide resolved
&& !flags.bools[key]
&& !flags.allBools
&& (aliases[key] ? !aliasIsBoolean(key) : true)
Expand Down
12 changes: 11 additions & 1 deletion test/dash.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ var parse = require('../');
var test = require('tape');

test('-', function (t) {
shadowspawn marked this conversation as resolved.
Show resolved Hide resolved
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: '---', _: [] });
});