yargs 10.0.3 → 11.0.0

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,64 @@
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
+ <a name="11.0.0"></a>
6
+ # [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Set implicit nargs=1 when type=number requiresArg=true ([#1050](https://github.com/yargs/yargs/issues/1050)) ([2b56812](https://github.com/yargs/yargs/commit/2b56812))
12
+
13
+
14
+ ### Features
15
+
16
+ * requiresArg is now simply an alias for nargs(1) ([#1054](https://github.com/yargs/yargs/issues/1054)) ([a3ddacc](https://github.com/yargs/yargs/commit/a3ddacc))
17
+
18
+
19
+ ### BREAKING CHANGES
20
+
21
+ * requiresArg now has significantly different error output, matching nargs.
22
+
23
+
24
+
25
+ <a name="10.1.2"></a>
26
+ ## [10.1.2](https://github.com/yargs/yargs/compare/v10.1.1...v10.1.2) (2018-01-17)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * requiresArg should only be enforced if argument exists ([#1043](https://github.com/yargs/yargs/issues/1043)) ([fbf41ae](https://github.com/yargs/yargs/commit/fbf41ae))
32
+
33
+
34
+
35
+ <a name="10.1.1"></a>
36
+ ## [10.1.1](https://github.com/yargs/yargs/compare/v10.1.0...v10.1.1) (2018-01-09)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * Add `dirname` sanity check on `findUp` ([#1036](https://github.com/yargs/yargs/issues/1036)) ([331d103](https://github.com/yargs/yargs/commit/331d103))
42
+
43
+
44
+
45
+ <a name="10.1.0"></a>
46
+ # [10.1.0](https://github.com/yargs/yargs/compare/v10.0.3...v10.1.0) (2018-01-01)
47
+
48
+
49
+ ### Bug Fixes
50
+
51
+ * 'undefined' should be taken to mean no argument was provided ([#1015](https://github.com/yargs/yargs/issues/1015)) ([c679e90](https://github.com/yargs/yargs/commit/c679e90))
52
+
53
+
54
+ ### Features
55
+
56
+ * add missing simple chinese locale strings ([#1004](https://github.com/yargs/yargs/issues/1004)) ([3cc24ec](https://github.com/yargs/yargs/commit/3cc24ec))
57
+ * add Norwegian Nynorsk translations ([#1028](https://github.com/yargs/yargs/issues/1028)) ([a5ac213](https://github.com/yargs/yargs/commit/a5ac213))
58
+ * async command handlers ([#1001](https://github.com/yargs/yargs/issues/1001)) ([241124b](https://github.com/yargs/yargs/commit/241124b))
59
+ * middleware ([#881](https://github.com/yargs/yargs/issues/881)) ([77b8dbc](https://github.com/yargs/yargs/commit/77b8dbc))
60
+
61
+
62
+
5
63
  <a name="10.0.3"></a>
6
64
  ## [10.0.3](https://github.com/yargs/yargs/compare/v10.0.2...v10.0.3) (2017-10-21)
7
65
 
package/README.md CHANGED
@@ -1,10 +1,5 @@
1
1
  # Yargs
2
2
 
3
- _Yargs is developed on evenings and weekends by
4
- volunteers. Why not grab them dinner or a drink?_
5
-
6
- [![Support via Gratipay](https://cdn.rawgit.com/gratipay/gratipay-badge/2.3.0/dist/gratipay.svg)](https://gratipay.com/yargs/)
7
-
8
3
  [![Build Status][travis-image]][travis-url]
9
4
  [![Coverage Status][coveralls-image]][coveralls-url]
10
5
  [![NPM version][npm-image]][npm-url]
package/lib/command.js CHANGED
@@ -11,27 +11,26 @@ const DEFAULT_MARKER = /(^\*)|(^\$0)/
11
11
  // arguments.
12
12
  module.exports = function command (yargs, usage, validation) {
13
13
  const self = {}
14
-
15
14
  let handlers = {}
16
15
  let aliasMap = {}
17
16
  let defaultCommand
18
- self.addHandler = function addHandler (cmd, description, builder, handler) {
17
+ self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) {
19
18
  let aliases = []
20
19
  handler = handler || (() => {})
21
-
20
+ middlewares = middlewares || []
22
21
  if (Array.isArray(cmd)) {
23
22
  aliases = cmd.slice(1)
24
23
  cmd = cmd[0]
25
24
  } else if (typeof cmd === 'object') {
26
25
  let command = (Array.isArray(cmd.command) || typeof cmd.command === 'string') ? cmd.command : moduleName(cmd)
27
26
  if (cmd.aliases) command = [].concat(command).concat(cmd.aliases)
28
- self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler)
27
+ self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares)
29
28
  return
30
29
  }
31
30
 
32
31
  // allow a module to be provided instead of separate builder and handler
33
32
  if (typeof builder === 'object' && builder.builder && typeof builder.handler === 'function') {
34
- self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler)
33
+ self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares)
35
34
  return
36
35
  }
37
36
 
@@ -50,6 +49,7 @@ module.exports = function command (yargs, usage, validation) {
50
49
  }
51
50
  return true
52
51
  })
52
+
53
53
  // standardize on $0 for default command.
54
54
  if (parsedAliases.length === 0 && isDefault) parsedAliases.push('$0')
55
55
 
@@ -74,6 +74,7 @@ module.exports = function command (yargs, usage, validation) {
74
74
  description: description,
75
75
  handler,
76
76
  builder: builder || {},
77
+ middlewares: middlewares || [],
77
78
  demanded: parsedCommand.demanded,
78
79
  optional: parsedCommand.optional
79
80
  }
@@ -225,7 +226,19 @@ module.exports = function command (yargs, usage, validation) {
225
226
 
226
227
  if (commandHandler.handler && !yargs._hasOutput()) {
227
228
  yargs._setHasOutput()
228
- commandHandler.handler(innerArgv)
229
+ if (commandHandler.middlewares.length > 0) {
230
+ const middlewareArgs = commandHandler.middlewares.reduce(function (initialObj, middleware) {
231
+ return Object.assign(initialObj, middleware(innerArgv))
232
+ }, {})
233
+ Object.assign(innerArgv, middlewareArgs)
234
+ }
235
+ const handlerResult = commandHandler.handler(innerArgv)
236
+ if (handlerResult && typeof handlerResult.then === 'function') {
237
+ handlerResult.then(
238
+ null,
239
+ (error) => yargs.getUsageInstance().fail(null, error)
240
+ )
241
+ }
229
242
  }
230
243
 
231
244
  if (command) {
package/lib/usage.js CHANGED
@@ -46,9 +46,9 @@ module.exports = function usage (yargs, y18n) {
46
46
  if (!failureOutput) {
47
47
  failureOutput = true
48
48
  if (showHelpOnFail) yargs.showHelp('error')
49
- if (msg) logger.error(msg)
49
+ if (msg || err) logger.error(msg || err)
50
50
  if (failMessage) {
51
- if (msg) logger.error('')
51
+ if (msg || err) logger.error('')
52
52
  logger.error(failMessage)
53
53
  }
54
54
  }
package/lib/validation.js CHANGED
@@ -54,38 +54,6 @@ module.exports = function validation (yargs, usage, y18n) {
54
54
  }
55
55
  }
56
56
 
57
- // make sure that any args that require an
58
- // value (--foo=bar), have a value.
59
- self.missingArgumentValue = function missingArgumentValue (argv) {
60
- const defaultValues = [true, false, '']
61
- const options = yargs.getOptions()
62
-
63
- if (options.requiresArg.length > 0) {
64
- const missingRequiredArgs = []
65
-
66
- options.requiresArg.forEach((key) => {
67
- const value = argv[key]
68
-
69
- // if a value is explicitly requested,
70
- // flag argument as missing if it does not
71
- // look like foo=bar was entered.
72
- if (~defaultValues.indexOf(value) ||
73
- (Array.isArray(value) && !value.length)) {
74
- missingRequiredArgs.push(key)
75
- }
76
- })
77
-
78
- if (missingRequiredArgs.length > 0) {
79
- usage.fail(__n(
80
- 'Missing argument value: %s',
81
- 'Missing argument values: %s',
82
- missingRequiredArgs.length,
83
- missingRequiredArgs.join(', ')
84
- ))
85
- }
86
- }
87
- }
88
-
89
57
  // make sure all the required arguments are present.
90
58
  self.requiredArguments = function requiredArguments (argv) {
91
59
  const demandedOptions = yargs.getDemandedOptions()
@@ -0,0 +1,39 @@
1
+ {
2
+ "Commands:": "Kommandoar:",
3
+ "Options:": "Alternativ:",
4
+ "Examples:": "Døme:",
5
+ "boolean": "boolsk",
6
+ "count": "mengd",
7
+ "string": "streng",
8
+ "number": "nummer",
9
+ "array": "matrise",
10
+ "required": "obligatorisk",
11
+ "default:": "standard:",
12
+ "choices:": "val:",
13
+ "generated-value": "generert-verdi",
14
+ "Not enough non-option arguments: got %s, need at least %s":
15
+ "Ikkje nok ikkje-alternativ argument: fekk %s, treng minst %s",
16
+ "Too many non-option arguments: got %s, maximum of %s":
17
+ "For mange ikkje-alternativ argument: fekk %s, maksimum %s",
18
+ "Missing argument value: %s": {
19
+ "one": "Manglar argumentverdi: %s",
20
+ "other": "Manglar argumentverdiar: %s"
21
+ },
22
+ "Missing required argument: %s": {
23
+ "one": "Manglar obligatorisk argument: %s",
24
+ "other": "Manglar obligatoriske argument: %s"
25
+ },
26
+ "Unknown argument: %s": {
27
+ "one": "Ukjent argument: %s",
28
+ "other": "Ukjende argument: %s"
29
+ },
30
+ "Invalid values:": "Ugyldige verdiar:",
31
+ "Argument: %s, Given: %s, Choices: %s": "Argument: %s, Gjeve: %s, Val: %s",
32
+ "Argument check failed: %s": "Argument sjekk mislukkast: %s",
33
+ "Implications failed:": "Konsekvensane mislukkast:",
34
+ "Not enough arguments following: %s": "Ikkje nok fylgande argument: %s",
35
+ "Invalid JSON config file: %s": "Ugyldig JSON konfigurasjonsfil: %s",
36
+ "Path to JSON config file": "Bane til JSON konfigurasjonsfil",
37
+ "Show help": "Vis hjelp",
38
+ "Show version number": "Vis versjonsnummer"
39
+ }
@@ -33,5 +33,9 @@
33
33
  "Invalid JSON config file: %s": "无效的 JSON 配置文件:%s",
34
34
  "Path to JSON config file": "JSON 配置文件的路径",
35
35
  "Show help": "显示帮助信息",
36
- "Show version number": "显示版本号"
36
+ "Show version number": "显示版本号",
37
+ "Did you mean %s?": "是指 %s?",
38
+ "Arguments %s and %s are mutually exclusive" : "选项 %s 和 %s 是互斥的",
39
+ "Positionals:": "位置:",
40
+ "command": "命令"
37
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "10.0.3",
3
+ "version": "11.0.0",
4
4
  "description": "yargs the modern, pirate-themed, successor to optimist.",
5
5
  "main": "./index.js",
6
6
  "files": [
@@ -12,7 +12,7 @@
12
12
  "LICENSE"
13
13
  ],
14
14
  "dependencies": {
15
- "cliui": "^3.2.0",
15
+ "cliui": "^4.0.0",
16
16
  "decamelize": "^1.1.1",
17
17
  "find-up": "^2.1.0",
18
18
  "get-caller-file": "^1.0.1",
@@ -23,10 +23,10 @@
23
23
  "string-width": "^2.0.0",
24
24
  "which-module": "^2.0.0",
25
25
  "y18n": "^3.2.1",
26
- "yargs-parser": "^8.0.0"
26
+ "yargs-parser": "^9.0.2"
27
27
  },
28
28
  "devDependencies": {
29
- "chai": "^3.4.1",
29
+ "chai": "^4.1.2",
30
30
  "chalk": "^1.1.3",
31
31
  "coveralls": "^2.11.11",
32
32
  "cpr": "^2.0.0",
package/yargs.js CHANGED
@@ -92,7 +92,7 @@ function Yargs (processArgs, cwd, parentRequire) {
92
92
  groups = {}
93
93
 
94
94
  const arrayOptions = [
95
- 'array', 'boolean', 'string', 'requiresArg', 'skipValidation',
95
+ 'array', 'boolean', 'string', 'skipValidation',
96
96
  'count', 'normalize', 'number'
97
97
  ]
98
98
 
@@ -204,7 +204,7 @@ function Yargs (processArgs, cwd, parentRequire) {
204
204
 
205
205
  self.requiresArg = function (keys) {
206
206
  argsert('<array|string>', [keys], arguments.length)
207
- populateParserHintArray('requiresArg', keys)
207
+ populateParserHintObject(self.nargs, false, 'narg', keys, 1)
208
208
  return self
209
209
  }
210
210
 
@@ -338,9 +338,9 @@ function Yargs (processArgs, cwd, parentRequire) {
338
338
  return self
339
339
  }
340
340
 
341
- self.command = function (cmd, description, builder, handler) {
342
- argsert('<string|array|object> [string|boolean] [function|object] [function]', [cmd, description, builder, handler], arguments.length)
343
- command.addHandler(cmd, description, builder, handler)
341
+ self.command = function (cmd, description, builder, handler, middlewares) {
342
+ argsert('<string|array|object> [string|boolean] [function|object] [function] [array]', [cmd, description, builder, handler, middlewares], arguments.length)
343
+ command.addHandler(cmd, description, builder, handler, middlewares)
344
344
  return self
345
345
  }
346
346
 
@@ -502,7 +502,7 @@ function Yargs (processArgs, cwd, parentRequire) {
502
502
  let obj = {}
503
503
  try {
504
504
  const pkgJsonPath = findUp.sync('package.json', {
505
- cwd: path || require('require-main-filename')(parentRequire || require),
505
+ cwd: path || require('path').dirname(require('require-main-filename')(parentRequire || require)),
506
506
  normalize: false
507
507
  })
508
508
  obj = JSON.parse(fs.readFileSync(pkgJsonPath))
@@ -964,6 +964,7 @@ function Yargs (processArgs, cwd, parentRequire) {
964
964
 
965
965
  options.__ = y18n.__
966
966
  options.configuration = pkgUp()['yargs'] || {}
967
+
967
968
  const parsed = Parser.detailed(args, options)
968
969
  let argv = parsed.argv
969
970
  if (parseContext) argv = Object.assign({}, argv, parseContext)
@@ -1106,7 +1107,6 @@ function Yargs (processArgs, cwd, parentRequire) {
1106
1107
  self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
1107
1108
  if (parseErrors) throw new YError(parseErrors.message)
1108
1109
  validation.nonOptionCount(argv)
1109
- validation.missingArgumentValue(argv)
1110
1110
  validation.requiredArguments(argv)
1111
1111
  if (strict) validation.unknownArguments(argv, aliases, positionalMap)
1112
1112
  validation.customChecks(argv, aliases)