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: unknown options terminated with digits now handled by unknown-options-as-args #238

Merged
merged 1 commit into from Feb 9, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -823,7 +823,7 @@ function parse (args, opts) {
// e.g. '-a-'
const flagEndingInHyphen = /^-+([^=]+?)-$/
// e.g. '-abc123'
const flagEndingInDigits = /^-+([^=]+?)\d+$/
const flagEndingInDigits = /^-+([^=]+?\d+)$/
// e.g. '-a/usr/local'
const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/
// check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
Expand Down
7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -4,10 +4,10 @@
"description": "the mighty option parser used by yargs",
"main": "index.js",
"scripts": {
"fix": "standard --fix",
"test": "c8 --reporter=text --reporter=html mocha test/*.js",
"posttest": "standard",
"coverage": "c8 report --reporter=text-lcov | coveralls",
"release": "standard-version"
"coverage": "c8 report --reporter=text-lcov | coveralls"
},
"repository": {
"url": "git@github.com:yargs/yargs-parser.git"
Expand All @@ -30,8 +30,7 @@
"chai": "^4.2.0",
"coveralls": "^3.0.2",
"mocha": "^5.2.0",
"standard": "^12.0.1",
"standard-version": "^6.0.0"
"standard": "^12.0.1"
},
"dependencies": {
"camelcase": "^5.0.0",
Expand Down
16 changes: 16 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -3011,6 +3011,22 @@ describe('yargs-parser', function () {
})
})
})

// See: https://github.com/yargs/yargs-parser/issues/231
it('should collect unknown options terminated with digit', function () {
const argv = parser('--known-arg=1 --num2', {
alias: { 'num': ['n'] },
number: ['known-arg'],
configuration: {
'unknown-options-as-args': true
}
})
argv.should.deep.equal({
_: ['--num2'],
'known-arg': 1,
'knownArg': 1
})
})
})

// addresses: https://github.com/yargs/yargs-parser/issues/41
Expand Down