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(halt-at-non-option): prevent known args from being parsed when "unknown-options-as-args" is enabled #438

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(halt-at-non-option): add failing scenario for when `unknown-opti…
…ons-as-args` is also enabled
  • Loading branch information
kherock committed Jul 18, 2022
commit 5f149be15165e52c9ed70587d25f874033f20767
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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the parsed output be prior to your fix? This output seems good, I'm just not 100% understanding the original bug.

Copy link
Contributor Author

@kherock kherock Jul 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized I must have screwed up the test assertion when I cleaned up these commits a while ago. I just amended the assertion so it matches the expected unknown-options-as-args behavior. Let me know if the output still looks good to you.

The full parsed output without the fix is

{ _: [ '-v', '--long', 'arg', './file.js', 'barbar' ], foo: true }

As you can see, yargs ignores halt-at-non-option and parses the --foo and -- options anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying, this fix looks right to me 👍

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