Skip to content

Commit

Permalink
Add support for hyphenated flags
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCrozier committed Sep 27, 2019
1 parent 48fe458 commit 81ae89e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ function validateInputArgv(argv) {
}

function getFlagIdentifier(flag) {
return flag.replace(/-+/g, '');
return flag.replace(/^-+/g, '');
}

function isFlag(value) {
return /^-[a-z]|--[a-z\d]+$/i.test(value);
return /^-[a-z]|--[a-z\d-]+$/i.test(value);
}

function isFlagGroup(value) {
Expand Down
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ describe('minimal-cli-parser', () => {
expect(parsed).to.have.property('_').that.contains('command');
});

it('should handle hyphenated flags', () => {
const parsed = parser(['command', '--output-path', './results', '--has-multiple-hyphens', '--has--odd---hyphen-usage']);

expect(parsed).to.have.property('output-path', './results');
expect(parsed).to.have.property('has-multiple-hyphens', true);
expect(parsed).to.have.property('has--odd---hyphen-usage', true);
});

it('should handle spacing consistently', () => {
const parsed = parser(['-a123', '-bc456', '--beta456', '--gamma=value1', '-d=value2', '-e', '-fg90', '-x', '7', '-y=8.9', '-z', '1.2']);

Expand Down

0 comments on commit 81ae89e

Please sign in to comment.