From 0d84196c5db8006dcbcd63b6a20fae648d5ba188 Mon Sep 17 00:00:00 2001 From: Kyle Herock Date: Fri, 5 Aug 2022 17:26:07 -0400 Subject: [PATCH 1/2] test(halt-at-non-option): add failing scenario for when `populate--` is enabled --- test/yargs-parser.cjs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/yargs-parser.cjs b/test/yargs-parser.cjs index 492e3b90..1608fec6 100644 --- a/test/yargs-parser.cjs +++ b/test/yargs-parser.cjs @@ -2997,6 +2997,17 @@ describe('yargs-parser', function () { }) }) + it('should push to _ when populate-- is true', function () { + const parse = parser( + ['--foo', './file.js', '--foo', '--', 'barbar', '--bar'], + { configuration: { 'halt-at-non-option': true, 'populate--': true }, boolean: ['foo', 'bar'] } + ) + parse.should.deep.equal({ + foo: true, + _: ['./file.js', '--foo', '--', 'barbar', '--bar'] + }) + }) + it('is not influenced by unknown options', function () { const parse = parser( ['-v', '--long', 'arg', './file.js', '--foo', '--', 'barbar'], From 5a09de236a1cbd53eb021e4e6ae77199d4ea93de Mon Sep 17 00:00:00 2001 From: Kyle Herock Date: Fri, 5 Aug 2022 17:26:56 -0400 Subject: [PATCH 2/2] fix(halt-at-non-option): push remaining args to `_` instead of `--` when a non-option is encountered --- lib/yargs-parser.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 764ca64e..3ca66151 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -395,7 +395,7 @@ export class YargsParser { notFlags = args.slice(i + 1) break } else if (configuration['halt-at-non-option']) { - notFlags = args.slice(i) + args.slice(i).forEach(pushPositional) break } else { pushPositional(arg)