From 802d7df078ac827abb3919b965974bd4553e1658 Mon Sep 17 00:00:00 2001 From: Chen Gang Date: Tue, 14 May 2019 15:22:42 +0800 Subject: [PATCH] fix: should populate "_" when given config with "short-option-groups" false issues: https://github.com/yargs/yargs-parser/issues/177 --- index.js | 2 +- test/yargs-parser.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ed54b8d6..3b772185 100644 --- a/index.js +++ b/index.js @@ -177,7 +177,7 @@ function parse (args, opts) { // -- seperated by space. } else if (arg.match(/^--.+/) || ( - !configuration['short-option-groups'] && arg.match(/^-.+/) + !configuration['short-option-groups'] && arg.match(/^-[^-]+/) )) { key = arg.match(/^--?(.+)/)[1] diff --git a/test/yargs-parser.js b/test/yargs-parser.js index fcff562a..6106e953 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -2442,6 +2442,19 @@ describe('yargs-parser', function () { result.should.not.have.property('--') }) + it('should populate "_" when given config with "short-option-groups" false', function () { + var result = parser.detailed([ + '--', 'foo' + ], { + configuration: { + 'short-option-groups': false + } + }) + result.argv.should.deep.equal({ '_': ['foo'] }) + result.argv.should.not.have.property('--') + result.newAliases.should.deep.equal({}) + }) + it('should populate the "--" if populate-- is "true"', function () { var result = parser([ '--name=meowmers', 'bare', '-cats', 'woo', 'moxy',