yargs 14.2.0 → 14.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [14.2.1](https://github.com/yargs/yargs/compare/v14.2.0...v14.2.1) (2019-10-30)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * stop-parse was not being respected by commands ([#1459](https://github.com/yargs/yargs/issues/1459)) ([e78e76e](https://github.com/yargs/yargs/commit/e78e76e3ac0551d4f30c71a05ddb21582960fcef))
11
+
5
12
  ## [14.2.0](https://github.com/yargs/yargs/compare/v14.1.0...v14.2.0) (2019-10-07)
6
13
 
7
14
 
package/lib/command.js CHANGED
@@ -227,9 +227,12 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
227
227
 
228
228
  if (commandHandler.handler && !yargs._hasOutput()) {
229
229
  yargs._setHasOutput()
230
+ // to simplify the parsing of positionals in commands,
231
+ // we temporarily populate '--' rather than _, with arguments
232
+ const populateDoubleDash = !!yargs.getOptions().configuration['populate--']
233
+ if (!populateDoubleDash) yargs._copyDoubleDash(innerArgv)
230
234
 
231
235
  innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false)
232
-
233
236
  let handlerResult
234
237
  if (isPromise(innerArgv)) {
235
238
  handlerResult = innerArgv.then(argv => commandHandler.handler(argv))
@@ -349,7 +352,12 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
349
352
  // short-circuit parse.
350
353
  if (!unparsed.length) return
351
354
 
352
- const parsed = Parser.detailed(unparsed, options)
355
+ const config = Object.assign({}, options.configuration, {
356
+ 'populate--': true
357
+ })
358
+ const parsed = Parser.detailed(unparsed, Object.assign({}, options, {
359
+ configuration: config
360
+ }))
353
361
 
354
362
  if (parsed.error) {
355
363
  yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "14.2.0",
3
+ "version": "14.2.1",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.js",
6
6
  "contributors": [
package/yargs.js CHANGED
@@ -1025,13 +1025,12 @@ function Yargs (processArgs, cwd, parentRequire) {
1025
1025
  enumerable: true
1026
1026
  })
1027
1027
 
1028
- self._parseArgs = function parseArgs (args, shortCircuit, _skipValidation, commandIndex) {
1029
- let skipValidation = !!_skipValidation
1028
+ self._parseArgs = function parseArgs (args, shortCircuit, _calledFromCommand, commandIndex) {
1029
+ let skipValidation = !!_calledFromCommand
1030
1030
  args = args || processArgs
1031
1031
 
1032
1032
  options.__ = y18n.__
1033
1033
  options.configuration = self.getParserConfiguration()
1034
-
1035
1034
  // Deprecated
1036
1035
  let pkgConfig = pkgUp()['yargs']
1037
1036
  if (pkgConfig) {
@@ -1039,7 +1038,14 @@ function Yargs (processArgs, cwd, parentRequire) {
1039
1038
  options.configuration = Object.assign({}, pkgConfig, options.configuration)
1040
1039
  }
1041
1040
 
1042
- const parsed = Parser.detailed(args, options)
1041
+ const populateDoubleDash = !!options.configuration['populate--']
1042
+ const config = Object.assign({}, options.configuration, {
1043
+ 'populate--': true
1044
+ })
1045
+ const parsed = Parser.detailed(args, Object.assign({}, options, {
1046
+ configuration: config
1047
+ }))
1048
+
1043
1049
  let argv = parsed.argv
1044
1050
  if (parseContext) argv = Object.assign({}, argv, parseContext)
1045
1051
  const aliases = parsed.aliases
@@ -1054,7 +1060,7 @@ function Yargs (processArgs, cwd, parentRequire) {
1054
1060
  // are two passes through the parser. If completion
1055
1061
  // is being performed short-circuit on the first pass.
1056
1062
  if (shortCircuit) {
1057
- return argv
1063
+ return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
1058
1064
  }
1059
1065
 
1060
1066
  // if there's a handler associated with a
@@ -1087,7 +1093,8 @@ function Yargs (processArgs, cwd, parentRequire) {
1087
1093
  // commands are executed using a recursive algorithm that executes
1088
1094
  // the deepest command first; we keep track of the position in the
1089
1095
  // argv._ array that is currently being executed.
1090
- return command.runCommand(cmd, self, parsed, i + 1)
1096
+ const innerArgv = command.runCommand(cmd, self, parsed, i + 1)
1097
+ return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
1091
1098
  } else if (!firstUnknownCommand && cmd !== completionCommand) {
1092
1099
  firstUnknownCommand = cmd
1093
1100
  break
@@ -1096,7 +1103,8 @@ function Yargs (processArgs, cwd, parentRequire) {
1096
1103
 
1097
1104
  // run the default command, if defined
1098
1105
  if (command.hasDefaultCommand() && !skipDefaultCommand) {
1099
- return command.runCommand(null, self, parsed)
1106
+ const innerArgv = command.runCommand(null, self, parsed)
1107
+ return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
1100
1108
  }
1101
1109
 
1102
1110
  // recommend a command if recommendCommands() has
@@ -1113,7 +1121,8 @@ function Yargs (processArgs, cwd, parentRequire) {
1113
1121
  self.exit(0)
1114
1122
  }
1115
1123
  } else if (command.hasDefaultCommand() && !skipDefaultCommand) {
1116
- return command.runCommand(null, self, parsed)
1124
+ const innerArgv = command.runCommand(null, self, parsed)
1125
+ return populateDoubleDash ? innerArgv : self._copyDoubleDash(innerArgv)
1117
1126
  }
1118
1127
 
1119
1128
  // we must run completions first, a user might
@@ -1131,7 +1140,7 @@ function Yargs (processArgs, cwd, parentRequire) {
1131
1140
 
1132
1141
  self.exit(0)
1133
1142
  })
1134
- return argv
1143
+ return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
1135
1144
  }
1136
1145
 
1137
1146
  // Handle 'help' and 'version' options
@@ -1175,6 +1184,16 @@ function Yargs (processArgs, cwd, parentRequire) {
1175
1184
  else throw err
1176
1185
  }
1177
1186
 
1187
+ return (populateDoubleDash || _calledFromCommand) ? argv : self._copyDoubleDash(argv)
1188
+ }
1189
+
1190
+ // to simplify the parsing of positionals in commands,
1191
+ // we temporarily populate '--' rather than _, with arguments
1192
+ // after the '--' directive. After the parse, we copy these back.
1193
+ self._copyDoubleDash = function (argv) {
1194
+ if (!argv._) return argv
1195
+ argv._.push.apply(argv._, argv['--'])
1196
+ delete argv['--']
1178
1197
  return argv
1179
1198
  }
1180
1199