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

Do not strip excess leading dashes on long option names #21

Merged
merged 3 commits into from
Dec 21, 2021
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
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const parseArgs = (
throw new Error('What are we doing with shortcodes!?!');
}

// Any number of leading dashes are allowed
// remove all leading dashes
arg = arg.replace(/^-+/, '');
arg = arg.slice(2); // remove leading --

if (arg.includes('=')) {
// withValue equals(=) case
Expand Down
11 changes: 11 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ test('args are passed "withValue" and "multiples"', function (t) {
t.end()
})

test('excess leading dashes on options are retained', function(t) {
// Enforce a design decision for an edge case.
const passedArgs = ['---triple'];
const passedOptions = { };
const expected = { flags: { '-triple': true}, values: { '-triple': [undefined]}, positionals: [] };
const args = parseArgs(passedArgs, passedOptions);

t.deepEqual(args, expected, 'excess option dashes are retained');

t.end();
});

//Test bad inputs

Expand Down