Skip to content

Commit

Permalink
fix(halt-at-non-option): prevent known args from being parsed when "u…
Browse files Browse the repository at this point in the history
…nknown-options-as-args" is enabled (#438)
  • Loading branch information
kherock authored Jul 19, 2022
1 parent fd30238 commit c474bc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class YargsParser {
let value: string

// any unknown option (except for end-of-options, "--")
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
if (arg !== '--' && /^-/.test(arg) && isUnknownOptionAsArg(arg)) {
pushPositional(arg)
// ---, ---=, ----, etc,
} else if (truncatedArg.match(/^---+(=|$)/)) {
Expand Down
10 changes: 10 additions & 0 deletions test/yargs-parser.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3008,6 +3008,16 @@ describe('yargs-parser', function () {
_: ['./file.js', '--foo', '--', 'barbar']
})
})

it('is not influenced by unknown options when "unknown-options-as-args" is true', function () {
const parse = parser(
['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'],
{ configuration: { 'halt-at-non-option': true, 'unknown-options-as-args': true }, boolean: ['foo'] }
)
parse.should.deep.equal({
_: ['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar']
})
})
})

describe('unknown-options-as-args = true', function () {
Expand Down

0 comments on commit c474bc1

Please sign in to comment.