Repository: yargs/yargs (js)

Issue:
positional arguments are not handled properly if parse() is used rather than .argv
see:

```js
var yargs = require('./yargs')([]);
yargs.command('foo <second>', 'the foo command', {}, function(argv) {
  console.log('command foo--', argv);
});
yargs.command('bar', 'the bar command', {}, function(argv){
  console.log('command bar--', argv);
});
console.log(yargs.parse(process.argv.slice(2)));
```

Pull request:
fix: positional arguments were not being handled appropriately by parse()
fixes #558

Patch:
diff --git a/lib/validation.js b/lib/validation.js
index b2cb2f6..d9a3364 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -219,6 +219,12 @@ module.exports = function (yargs, usage, y18n) {
     const implyFail = []
 
     Object.keys(implied).forEach(function (key) {
+      var booleanNegation
+      if (yargs.getOptions().configuration['boolean-negation'] === false) {
+        booleanNegation = false
+      } else {
+        booleanNegation = true
+      }
       var num
       const origKey = key
       var value = implied[key]
@@ -230,7 +236,7 @@ module.exports = function (yargs, usage, y18n) {
       if (typeof key === 'number') {
         // check length of argv._
         key = argv._.length >= key
-      } else if (key.match(/^--no-.+/)) {
+      } else if (key.match(/^--no-.+/) && booleanNegation) {
         // check if key doesn't exist
         key = key.match(/^--no-(.+)/)[1]
         key = !argv[key]
@@ -244,7 +250,7 @@ module.exports = function (yargs, usage, y18n) {
 
       if (typeof value === 'number') {
         value = argv._.length >= value
-      } else if (value.match(/^--no-.+/)) {
+      } else if (value.match(/^--no-.+/) && booleanNegation) {
         value = value.match(/^--no-(.+)/)[1]
         value = !argv[value]
       } else {
diff --git a/yargs.js b/yargs.js
index 8d90028..ed6fd56 100644
--- a/yargs.js
+++ b/yargs.js
@@ -373,6 +373,7 @@ function Yargs (processArgs, cwd, parentRequire) {
   }
 
   self.parse = function (args, shortCircuit) {
+    if (!shortCircuit) processArgs = args
     return parseArgs(args, shortCircuit)
   }
 
@@ -636,7 +637,7 @@ function Yargs (processArgs, cwd, parentRequire) {
 
   function parseArgs (args, shortCircuit) {
     options.__ = y18n.__
-    options.configuration = pkgUp()['yargs'] || {}
+    options.configuration = pkgUp(cwd)['yargs'] || {}
     const parsed = Parser.detailed(args, options)
     const argv = parsed.argv
     var aliases = parsed.aliases


Test patch:
diff --git a/test/command.js b/test/command.js
index f7729d6..96ad4c4 100644
--- a/test/command.js
+++ b/test/command.js
@@ -485,4 +485,12 @@ describe('Command', function () {
     output.should.include('bar')
     output.should.not.include('foo')
   })
+
+  // addresses https://github.com/yargs/yargs/issues/558
+  it('handles positional arguments if command is invoked using .parse()', function () {
+    var y = yargs([])
+      .command('foo <second>', 'the foo command', {})
+    var argv = y.parse(['foo', 'bar'])
+    argv.second.should.equal('bar')
+  })
 })
diff --git a/test/fixtures/package.json b/test/fixtures/package.json
index 20be857..7927de4 100644
--- a/test/fixtures/package.json
+++ b/test/fixtures/package.json
@@ -4,6 +4,7 @@
     "type": "svn"
   },
   "yargs": {
-    "dot-notation": false
+    "dot-notation": false,
+    "boolean-negation": false
   }
 }
diff --git a/test/validation.js b/test/validation.js
index ac0b48a..641b22f 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -57,6 +57,18 @@ describe('validation tests', function () {
         })
         .argv
     })
+
+    it('does not treat --no- as a special case if boolean negation is disabled', function (done) {
+      yargs(['--foo'], './test/fixtures')
+        .implies({
+          'foo': '--no-foo'
+        })
+        .fail(function (msg) {
+          msg.should.match(/Implications failed/)
+          return done()
+        })
+        .argv
+    })
   })
 
   describe('demand', function () {