Repository: yargs/yargs-parser
Pull request #179 (2019-05-14 07:31:20)

fix: should populate "_" when "short-option-groups" is false
fix: should populate "_" when given config with "short-option-groups" false
issues: https://github.com/yargs/yargs-parser/issues/177


Patch:
diff --git a/README.md b/README.md
index 5ddc3fa..dde9f84 100644
--- a/README.md
+++ b/README.md
@@ -58,21 +58,24 @@ Parses command line arguments returning a simple mapping of keys and values.
 * `args`: a string or array of strings representing the options to parse.
 * `opts`: provide a set of hints indicating how `args` should be parsed:
   * `opts.alias`: an object representing the set of aliases for a key: `{alias: {foo: ['f']}}`.
-  * `opts.array`: indicate that keys should be parsed as an array: `{array: ['foo', 'bar']}`.
-     Indicate that keys should be parsed as an array and coerced to booleans / numbers:
-     `{array: [{ key: 'foo', boolean: true }, {key: 'bar', number: true}]}`.
+  * `opts.array`: indicate that keys should be parsed as an array: `{array: ['foo', 'bar']}`.<br>
+    Indicate that keys should be parsed as an array and coerced to booleans / numbers:<br>
+    `{array: [{ key: 'foo', boolean: true }, {key: 'bar', number: true}]}`.
   * `opts.boolean`: arguments should be parsed as booleans: `{boolean: ['x', 'y']}`.
-  * `opts.config`: indicate a key that represents a path to a configuration file (this file will be loaded and parsed).
   * `opts.coerce`: provide a custom synchronous function that returns a coerced value from the argument provided
-    (or throws an error), e.g. `{coerce: {foo: function (arg) {return modifiedArg}}}`.
+    (or throws an error). For arrays the function is called only once for the entire array:<br>
+    `{coerce: {foo: function (arg) {return modifiedArg}}}`.
+  * `opts.config`: indicate a key that represents a path to a configuration file (this file will be loaded and parsed).
+  * `opts.configObjects`: configuration objects to parse, their properties will be set as arguments:<br>
+    `{configObjects: [{'x': 5, 'y': 33}, {'z': 44}]}`.
+  * `opts.configuration`: provide configuration options to the yargs-parser (see: [configuration](#configuration)).
   * `opts.count`: indicate a key that should be used as a counter, e.g., `-vvv` = `{v: 3}`.
   * `opts.default`: provide default values for keys: `{default: {x: 33, y: 'hello world!'}}`.
   * `opts.envPrefix`: environment variables (`process.env`) with the prefix provided should be parsed.
   * `opts.narg`: specify that a key requires `n` arguments: `{narg: {x: 2}}`.
   * `opts.normalize`: `path.normalize()` will be applied to values set to this key.
-  * `opts.string`: keys should be treated as strings (even if they resemble a number `-x 33`).
-  * `opts.configuration`: provide configuration options to the yargs-parser (see: [configuration](#configuration)).
   * `opts.number`: keys should be treated as numbers.
+  * `opts.string`: keys should be treated as strings (even if they resemble a number `-x 33`).
 
 **returns:**
 
diff --git a/index.js b/index.js
index ed54b8d..3b77218 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]
 


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index fcff562..6106e95 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',