Skip to content

Commit

Permalink
fix: do not strip excess leading dashes on long option names (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Dec 21, 2021
1 parent 80843da commit f848590
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit f848590

Please sign in to comment.