nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: yargs/yargs
Pull request #624 (2016-09-14 15:58:04)

make opts object not required anymore for .option()
Usually, yargs always requires options to be featuring an object for customisation like so:
```javascript
yargs()
  .option('x', {})
  .argv
```

This however seemed strange to me, as said customisation never is needed, you can also use options without any further customisation.

This Pull Request removes the check for whether an object is given to allow for declaration of options like this:
```javascript
yargs()
  .option('x')
  .argv
```

Why would we do that? Because it the object isn't needed anyway, requiring it makes little sense, and it might be confusing to people. Also, some people (like me) might prefer to write down all options in the yargs configuration to make clear which ones exist, also making yargs list them in the `argv` object even if not passed.

bcoe: @maxrimue love it! sorry I've been slightly AWOL. `ETOOMUCHOSS`

Patch:
diff --git a/README.md b/README.md
index 1f441f9..5547ca6 100644
--- a/README.md
+++ b/README.md
@@ -1082,8 +1082,8 @@ For example:
 
 ```js
 require('yargs')
-  .option('foobar', {})
-  .option('foobaz', {})
+  .option('foobar')
+  .option('foobaz')
   .completion()
   .getCompletion(['./test.js', '--foo'], function (completions) {
     console.log(completions)
@@ -1310,13 +1310,14 @@ var argv = require('yargs')
   .argv
 ```
 
-.option(key, opt)
+.option(key, [opt])
 -----------------
-.options(key, opt)
+.options(key, [opt])
 ------------------
 
-Instead of chaining together `.alias().demand().default().describe().string()`, you can specify
-keys in `opt` for each of the chainable methods.
+This method can be used to make yargs aware of options that _could_
+exist. You can also pass an `opt` object which can hold further
+customization, like `.alias()`, `.demand()` etc. for that option.
 
 For example:
 
diff --git a/yargs.js b/yargs.js
index 99c102f..13fd676 100644
--- a/yargs.js
+++ b/yargs.js
@@ -1,4 +1,3 @@
-const assert = require('assert')
 const Command = require('./lib/command')
 const Completion = require('./lib/completion')
 const Parser = require('yargs-parser')
@@ -394,7 +393,9 @@ function Yargs (processArgs, cwd, parentRequire) {
         self.options(k, key[k])
       })
     } else {
-      assert(typeof opt === 'object', 'second argument to option must be an object')
+      if (typeof opt !== 'object') {
+        opt = {}
+      }
 
       options.key[key] = true // track manually set keys.
 


Test patch:
diff --git a/test/yargs.js b/test/yargs.js
index a349264..703ce40 100644
--- a/test/yargs.js
+++ b/test/yargs.js
@@ -124,6 +124,16 @@ describe('yargs dsl tests', function () {
     })
   })
 
+  it('should not require config object for an option', function () {
+    var r = checkOutput(function () {
+      return yargs([])
+        .option('x')
+        .argv
+    })
+
+    expect(r.errors).to.deep.equal([])
+  })
+
   describe('showHelpOnFail', function () {
     it('should display custom failure message, if string is provided as first argument', function () {
       var r = checkOutput(function () {
Repository: yargs/yargs
Pull request #634 (2016-09-26 06:00:54)

chore: add greenkeeper ignore rule for string-width, which no longer Node 0.10
I'd like to continue supporting Node 0.10 in the medium term, since this is a widely used utility library.


Patch:
diff --git a/package.json b/package.json
index 59ecaac..f4d7e59 100644
--- a/package.json
+++ b/package.json
@@ -33,12 +33,12 @@
     "coveralls": "^2.11.11",
     "cpr": "^2.0.0",
     "cross-spawn": "^4.0.0",
-    "es6-promise": "^3.0.2",
+    "es6-promise": "^4.0.2",
     "hashish": "0.0.4",
     "mocha": "^3.0.1",
     "nyc": "^8.1.0",
     "rimraf": "^2.5.0",
-    "standard": "^8.0.0",
+    "standard": "^8.2.0",
     "standard-version": "^2.2.1",
     "which": "^1.2.9"
   },
@@ -70,5 +70,10 @@
   "license": "MIT",
   "engine": {
     "node": ">=0.10"
+  },
+  "greenkeeper": {
+    "ignore": [
+      "string-width"
+    ]
   }
 }
diff --git a/yargs.js b/yargs.js
index 13fd676..7dac74d 100644
--- a/yargs.js
+++ b/yargs.js
@@ -824,7 +824,7 @@ function Yargs (processArgs, cwd, parentRequire) {
     // Check if any of the options to skip validation were provided
     if (!skipValidation && options.skipValidation.length > 0) {
       skipValidation = Object.keys(argv).some(function (key) {
-        return options.skipValidation.indexOf(key) >= 0
+        return options.skipValidation.indexOf(key) >= 0 && argv[key] === true
       })
     }
 


Test patch:
diff --git a/test/yargs.js b/test/yargs.js
index 703ce40..75d129d 100644
--- a/test/yargs.js
+++ b/test/yargs.js
@@ -1051,6 +1051,20 @@ describe('yargs dsl tests', function () {
           .argv
       argv.koala.should.equal(true)
     })
+
+    it('allows having an option that skips validation but not skipping validation if that option is not used', function () {
+      var skippedValidation = true
+      yargs(['--no-skip'])
+          .demand(5)
+          .option('skip', {
+            skipValidation: true
+          })
+          .fail(function (msg) {
+            skippedValidation = false
+          })
+          .argv
+      expect(skippedValidation).to.equal(false)
+    })
   })
 
   describe('.help()', function () {
Repository: yargs/yargs
Pull request #704 (2016-11-13 18:33:51)

chore: add camelcase to greenkeeper ignore, until we drop 0.10 support


Patch:
diff --git a/README.md b/README.md
index 7947ad3..a0b9ced 100644
--- a/README.md
+++ b/README.md
@@ -1150,15 +1150,17 @@ yargs have been validated.
 
 Method to execute when a failure occurs, rather than printing the failure message.
 
-`fn` is called with the failure message that would have been printed and the
-`Error` instance originally thrown, if any.
+`fn` is called with the failure message that would have been printed, the
+`Error` instance originally thrown and yargs state when the failure
+occured. 
 
 ```js
 var argv = require('yargs')
-  .fail(function (msg, err) {
+  .fail(function (msg, err, yargs) {
     if (err) throw err // preserve stack
     console.error('You broke it!')
     console.error(msg)
+    console.error('You should be doing', yargs.help())
     process.exit(1)
   })
   .argv
diff --git a/lib/usage.js b/lib/usage.js
index 9b3e3e1..7f62275 100644
--- a/lib/usage.js
+++ b/lib/usage.js
@@ -34,7 +34,7 @@ module.exports = function (yargs, y18n) {
 
     if (fails.length) {
       for (var i = fails.length - 1; i >= 0; --i) {
-        fails[i](msg, err)
+        fails[i](msg, err, self)
       }
     } else {
       if (yargs.getExitProcess()) setBlocking(true)
diff --git a/package.json b/package.json
index eaa2d76..f43370b 100644
--- a/package.json
+++ b/package.json
@@ -74,7 +74,8 @@
   "greenkeeper": {
     "ignore": [
       "string-width",
-      "read-pkg-up"
+      "read-pkg-up",
+      "camelcase"
     ]
   }
 }
diff --git a/yargs.js b/yargs.js
index 4c53ed3..b0693c0 100644
--- a/yargs.js
+++ b/yargs.js
@@ -416,7 +416,8 @@ function Yargs (processArgs, cwd, parentRequire) {
     var obj = {}
     try {
       obj = readPkgUp.sync({
-        cwd: path || require('require-main-filename')(parentRequire || require)
+        cwd: path || require('require-main-filename')(parentRequire || require),
+        normalize: false
       })
     } catch (noop) {}
 


Test patch:
diff --git a/test/usage.js b/test/usage.js
index e5e83ed..d8781de 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -473,6 +473,28 @@ describe('usage tests', function () {
         r.logs.should.deep.equal(['foo'])
         r.should.have.property('exit').and.be.false
       })
+
+      it('is invoked with yargs instance as third argument', function () {
+        var r = checkUsage(function () {
+          return yargs('foo')
+            .command('foo', 'desc', {
+              bar: {
+                describe: 'bar command'
+              }
+            }, function (argv) {
+              throw new Error('blah')
+            })
+            .fail(function (message, error, yargs) {
+              yargs.showHelp()
+            })
+            .exitProcess(false)
+            .wrap(null)
+            .argv
+        })
+
+        r.errors[0].should.contain('bar command')
+      })
+
       describe('when check() throws error', function () {
         it('fail() is called with the original error object as the second parameter', function () {
           var r = checkUsage(function () {
Repository: yargs/yargs
Pull request #705 (2016-11-13 18:49:39)

perf: normalizing package data is an expensive operation
For yargs' purposes, we do not need package information normalized (this involves checking license strings, applying semver, etc). The normalize step is also a fairly expensive operation.


Patch:
diff --git a/README.md b/README.md
index 7947ad3..a0b9ced 100644
--- a/README.md
+++ b/README.md
@@ -1150,15 +1150,17 @@ yargs have been validated.
 
 Method to execute when a failure occurs, rather than printing the failure message.
 
-`fn` is called with the failure message that would have been printed and the
-`Error` instance originally thrown, if any.
+`fn` is called with the failure message that would have been printed, the
+`Error` instance originally thrown and yargs state when the failure
+occured. 
 
 ```js
 var argv = require('yargs')
-  .fail(function (msg, err) {
+  .fail(function (msg, err, yargs) {
     if (err) throw err // preserve stack
     console.error('You broke it!')
     console.error(msg)
+    console.error('You should be doing', yargs.help())
     process.exit(1)
   })
   .argv
diff --git a/lib/usage.js b/lib/usage.js
index 9b3e3e1..7f62275 100644
--- a/lib/usage.js
+++ b/lib/usage.js
@@ -34,7 +34,7 @@ module.exports = function (yargs, y18n) {
 
     if (fails.length) {
       for (var i = fails.length - 1; i >= 0; --i) {
-        fails[i](msg, err)
+        fails[i](msg, err, self)
       }
     } else {
       if (yargs.getExitProcess()) setBlocking(true)
diff --git a/yargs.js b/yargs.js
index 4c53ed3..b0693c0 100644
--- a/yargs.js
+++ b/yargs.js
@@ -416,7 +416,8 @@ function Yargs (processArgs, cwd, parentRequire) {
     var obj = {}
     try {
       obj = readPkgUp.sync({
-        cwd: path || require('require-main-filename')(parentRequire || require)
+        cwd: path || require('require-main-filename')(parentRequire || require),
+        normalize: false
       })
     } catch (noop) {}
 


Test patch:
diff --git a/test/usage.js b/test/usage.js
index e5e83ed..d8781de 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -473,6 +473,28 @@ describe('usage tests', function () {
         r.logs.should.deep.equal(['foo'])
         r.should.have.property('exit').and.be.false
       })
+
+      it('is invoked with yargs instance as third argument', function () {
+        var r = checkUsage(function () {
+          return yargs('foo')
+            .command('foo', 'desc', {
+              bar: {
+                describe: 'bar command'
+              }
+            }, function (argv) {
+              throw new Error('blah')
+            })
+            .fail(function (message, error, yargs) {
+              yargs.showHelp()
+            })
+            .exitProcess(false)
+            .wrap(null)
+            .argv
+        })
+
+        r.errors[0].should.contain('bar command')
+      })
+
       describe('when check() throws error', function () {
         it('fail() is called with the original error object as the second parameter', function () {
           var r = checkUsage(function () {
Repository: yargs/yargs
Pull request #750 (2017-01-06 05:53:39)

fix: address min/max validation message regression
@kumar303 pointed out a regression we accidentally introduced, in the process of reworking the command logic.

@kumar303, thanks for appreciating the nice CHANGELOG, we owe it to the [standard-version](https://github.com/conventional-changelog/standard-version) project which grew out of @nexdrew and my work at npm and on yargs.


Patch:
diff --git a/yargs.js b/yargs.js
index a63c94a..8ee528e 100644
--- a/yargs.js
+++ b/yargs.js
@@ -318,7 +318,7 @@ function Yargs (processArgs, cwd, parentRequire) {
     }
 
     if (typeof keys === 'number') {
-      self.demandCommand(keys, max, msg)
+      self.demandCommand(keys, max, msg, msg)
     } else if (Array.isArray(keys)) {
       keys.forEach(function (key) {
         self.demandOption(key, msg)


Test patch:
diff --git a/test/validation.js b/test/validation.js
index 14d864b..7b79e2f 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -239,6 +239,17 @@ describe('validation tests', function () {
         .argv
     })
 
+    // address regression in: https://github.com/yargs/yargs/pull/740
+    it('custom failure message should be printed for both min and max constraints', function (done) {
+      yargs(['foo'])
+        .demand(0, 0, 'hey! give me a custom exit message')
+        .fail(function (msg) {
+          expect(msg).to.equal('hey! give me a custom exit message')
+          return done()
+        })
+        .argv
+    })
+
     it('interprets min relative to command', function () {
       var failureMsg
       yargs('lint')
Repository: yargs/yargs
Pull request #805 (2017-02-26 09:42:25)

fix: positional arguments of sub-command
fixes: #795 

positional arguments in sub-commands aren't white-listed for `strict()`.


Patch:
diff --git a/.editorconfig b/.editorconfig
deleted file mode 100644
index 91c3361..0000000
--- a/.editorconfig
+++ /dev/null
@@ -1,7 +0,0 @@
-root = true
-
-[*.js]
-end_of_line = lf
-indent_style = space
-indent_size = 2
-insert_final_newline = true
diff --git a/lib/command.js b/lib/command.js
index 27fe6d0..c49555a 100644
--- a/lib/command.js
+++ b/lib/command.js
@@ -224,9 +224,10 @@ module.exports = function (yargs, usage, validation) {
 
     // we apply validation post-hoc, so that custom
     // checks get passed populated positional arguments.
-    yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)
+    if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)
 
     if (commandHandler.handler && !yargs._hasOutput()) {
+      yargs._setHasOutput()
       commandHandler.handler(innerArgv)
     }
 
diff --git a/yargs.js b/yargs.js
index 1843443..2b911d9 100644
--- a/yargs.js
+++ b/yargs.js
@@ -897,6 +897,10 @@ function Yargs (processArgs, cwd, parentRequire) {
     return hasOutput
   }
 
+  self._setHasOutput = function () {
+    hasOutput = true
+  }
+
   var recommendCommands
   self.recommendCommands = function (recommend) {
     argsert('[boolean]', [recommend], arguments.length)


Test patch:
diff --git a/test/command.js b/test/command.js
index dfa5c70..a792653 100644
--- a/test/command.js
+++ b/test/command.js
@@ -1024,6 +1024,19 @@ describe('Command', function () {
           })
       })
 
+      // address https://github.com/yargs/yargs/issues/795
+      it('does not fail strict check due to postional command arguments in nested commands', function (done) {
+        yargs()
+          .strict()
+          .command('hi', 'The hi command', function (yargs) {
+            yargs.command('ben <age>', 'ben command', function () {}, function () {})
+          })
+          .parse('hi ben 99', function (err, argv, output) {
+            expect(err).to.equal(null)
+            return done()
+          })
+      })
+
       it('does not fire command if validation fails', function (done) {
         var commandRun = false
         yargs()
Repository: yargs/yargs
Pull request #820 (2017-03-09 19:59:04)

fix: populating placeholder arguments broke validation
yikes, because we populate placeholder keys for arguments it broke `demand` logic in commands.


Patch:
diff --git a/lib/validation.js b/lib/validation.js
index 3d3dbf5..0c2502f 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -89,7 +89,7 @@ module.exports = function (yargs, usage, y18n) {
     var missing = null
 
     Object.keys(demandedOptions).forEach(function (key) {
-      if (!argv.hasOwnProperty(key)) {
+      if (!argv.hasOwnProperty(key) || typeof argv[key] === 'undefined') {
         missing = missing || {}
         missing[key] = demandedOptions[key]
       }


Test patch:
diff --git a/test/command.js b/test/command.js
index a792653..0af0929 100644
--- a/test/command.js
+++ b/test/command.js
@@ -1299,4 +1299,22 @@ describe('Command', function () {
       })
     })
   })
+
+  // addresses: https://github.com/yargs/yargs/issues/819
+  it('should kick along [demand] configuration to commands', function () {
+    var called = false
+    var r = checkOutput(function () {
+      yargs('foo')
+        .command('foo', 'foo command', function () {}, function (argv) {
+          called = true
+        })
+        .option('bar', {
+          describe: 'a foo command',
+          demand: true
+        })
+        .argv
+    })
+    called.should.equal(false)
+    r.errors.should.match(/Missing required argument/)
+  })
 })
Repository: yargs/yargs
Pull request #954 (2017-09-14 19:44:11)

fix: implications fails only displayed once
Regarding https://github.com/yargs/yargs/pull/922#issuecomment-329473901

bcoe: @Morishiri good find. @MattSturgeon are you happy with this fix?
bcoe: @Morishiri thanks for the fix. Feel free to join the community Slack if you feel like hanging out and contributing more to the project:

http://devtoolscommunity.herokuapp.com/

Patch:
diff --git a/lib/validation.js b/lib/validation.js
index 0b322a3..1eee2fb 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -249,6 +249,7 @@ module.exports = function validation (yargs, usage, y18n) {
       ;(implied[key] || []).forEach((value) => {
         let num
         let key = origKey
+        const origValue = value
 
         // convert string '1' to number 1
         num = Number(key)
@@ -278,7 +279,7 @@ module.exports = function validation (yargs, usage, y18n) {
           value = argv[value]
         }
         if (key && !value) {
-          implyFail.push(origKey)
+          implyFail.push(` ${origKey} -> ${origValue}`)
         }
       })
     })
@@ -286,12 +287,8 @@ module.exports = function validation (yargs, usage, y18n) {
     if (implyFail.length) {
       let msg = `${__('Implications failed:')}\n`
 
-      implyFail.forEach((key) => {
-        if (implied[key]) {
-          implied[key].forEach((value) => {
-            msg += (` ${key} -> ${value}`)
-          })
-        }
+      implyFail.forEach((value) => {
+        msg += (value)
       })
 
       usage.fail(msg)


Test patch:
diff --git a/test/validation.js b/test/validation.js
index b65c19f..ff9a607 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -38,15 +38,17 @@ describe('validation tests', () => {
         .argv
     })
 
-    it('fails if either implied argument is not set', (done) => {
+    it('fails if either implied argument is not set and displays only failed', (done) => {
       yargs(['-f', '-b'])
           .implies('f', ['b', 'c'])
           .fail((msg1) => {
             yargs(['-f', '-c'])
                 .implies('f', ['b', 'c'])
                 .fail((msg2) => {
-                  msg1.should.match(/f -> b f -> c/)
-                  msg2.should.match(/f -> b f -> c/)
+                  msg1.should.match(/f -> c/)
+                  msg1.should.not.match(/f -> b/)
+                  msg2.should.match(/f -> b/)
+                  msg2.should.not.match(/f -> c/)
                   return done()
                 })
                 .argv
Repository: yargs/yargs
Pull request #973 (2017-10-13 06:54:56)

docs: switch to using .positional() in example
show off the new `.positional()` method.


Patch:
diff --git a/README.md b/README.md
index 2c08221..d16b82d 100644
--- a/README.md
+++ b/README.md
@@ -56,11 +56,12 @@ Retreat from the xupptumblers!
 ```js
 #!/usr/bin/env node
 require('yargs') // eslint-disable-line
-  .command('serve', 'start the server', (yargs) => {
-    yargs.option('port', {
-      describe: 'port to bind on',
-      default: 5000
-    })    
+  .command('serve [port]', 'start the server', (yargs) => {
+    yargs
+      .positional('port', {
+        describe: 'port to bind on',
+        default: 5000
+      })
   }, (argv) => {
     if (argv.verbose) console.info(`start server on :${argv.port}`)
     serve(argv.port)
diff --git a/yargs.js b/yargs.js
index 08569fc..21c4c9b 100644
--- a/yargs.js
+++ b/yargs.js
@@ -647,7 +647,7 @@ function Yargs (processArgs, cwd, parentRequire) {
       }
 
       const desc = opt.describe || opt.description || opt.desc
-      if (desc) {
+      if (!opt.hidden) {
         self.describe(key, desc)
       }
 


Test patch:
diff --git a/test/usage.js b/test/usage.js
index 78592e0..c97592a 100644
--- a/test/usage.js
+++ b/test/usage.js
@@ -2314,10 +2314,12 @@ describe('usage tests', () => {
       const r = checkUsage(() => yargs(['--help'])
           .option('answer', {
             type: 'string',
-            choices: ['yes', 'no', 'maybe']
+            choices: ['yes', 'no', 'maybe'],
+            hidden: true
           })
           .option('confidence', {
-            choices: [0, 25, 50, 75, 100]
+            choices: [0, 25, 50, 75, 100],
+            hidden: true
           })
           .wrap(null)
           .argv
@@ -2698,4 +2700,31 @@ describe('usage tests', () => {
       ])
     })
   })
+
+  describe('hidden options', () => {
+    it('--help should display all options except for hidden ones', () => {
+      const r = checkUsage(() => yargs('--help')
+          .options({
+            foo: {
+              describe: 'FOO'
+            },
+            bar: {},
+            baz: {
+              describe: 'BAZ',
+              hidden: true
+            }
+          })
+          .argv
+        )
+
+      r.logs[0].split('\n').should.deep.equal([
+        'Options:',
+        '  --help     Show help                                                 [boolean]',
+        '  --version  Show version number                                       [boolean]',
+        '  --foo      FOO',
+        '  --bar',
+        ''
+      ])
+    })
+  })
 })
Repository: yargs/yargs
Pull request #984 (2017-10-16 04:39:32)

fix: the positional argument parse step was clobbering global flag arguments


Patch:
diff --git a/lib/command.js b/lib/command.js
index b528df7..b094ad5 100644
--- a/lib/command.js
+++ b/lib/command.js
@@ -293,13 +293,26 @@ module.exports = function command (yargs, usage, validation) {
         return `--${key} ${value}`
       }))
     })
+
+    // short-circuit parse.
+    if (!unparsed.length) return
+
     const parsed = Parser.detailed(unparsed.join(' '), options)
 
     if (parsed.error) {
       yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
     } else {
+      // only copy over positional keys (don't overwrite
+      // flag arguments that were already parsed).
+      const positionalKeys = Object.keys(positionalMap)
+      Object.keys(positionalMap).forEach((key) => {
+        [].push.apply(positionalKeys, parsed.aliases[key])
+      })
+
       Object.keys(parsed.argv).forEach((key) => {
-        if (key !== '_') argv[key] = parsed.argv[key]
+        if (positionalKeys.indexOf(key) !== -1) {
+          argv[key] = parsed.argv[key]
+        }
       })
     }
   }
diff --git a/locales/tr.json b/locales/tr.json
index 000060b..9b06c52 100644
--- a/locales/tr.json
+++ b/locales/tr.json
@@ -35,5 +35,7 @@
   "Path to JSON config file": "JSON yapılandırma dosya konumu",
   "Show help": "Yardım detaylarını göster",
   "Show version number": "Versiyon detaylarını göster",
-  "Did you mean %s?": "Bunu mu demek istediniz: %s?"
+  "Did you mean %s?": "Bunu mu demek istediniz: %s?",
+  "Positionals:": "Sıralılar:",
+  "command": "komut"
 }


Test patch:
diff --git a/test/command.js b/test/command.js
index d468f90..1f303db 100644
--- a/test/command.js
+++ b/test/command.js
@@ -102,6 +102,15 @@ describe('Command', () => {
       expect(handlers.wat).to.not.exist
       command.getCommands().should.deep.equal(['foo', 'wat'])
     })
+
+    it('does not overwrite existing values in argv for keys that are not positional', () => {
+      const argv = yargs('foo foo.js --reporter=html')
+        .command('foo <file>')
+        .default('reporter', 'text')
+        .argv
+      argv.file.should.equal('foo.js')
+      argv.reporter.should.equal('html')
+    })
   })
 
   describe('variadic', () => {