Skip to content

Commit f848590

Browse files
authored
fix: do not strip excess leading dashes on long option names (#21)
1 parent 80843da commit f848590

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ const parseArgs = (
3131
throw new Error('What are we doing with shortcodes!?!');
3232
}
3333

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

3836
if (arg.includes('=')) {
3937
// withValue equals(=) case

test/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ test('args are passed "withValue" and "multiples"', function (t) {
6868
t.end()
6969
})
7070

71+
test('excess leading dashes on options are retained', function(t) {
72+
// Enforce a design decision for an edge case.
73+
const passedArgs = ['---triple'];
74+
const passedOptions = { };
75+
const expected = { flags: { '-triple': true}, values: { '-triple': [undefined]}, positionals: [] };
76+
const args = parseArgs(passedArgs, passedOptions);
77+
78+
t.deepEqual(args, expected, 'excess option dashes are retained');
79+
80+
t.end();
81+
});
7182

7283
//Test bad inputs
7384

0 commit comments

Comments
 (0)