yargs 10.0.2 → 10.1.2

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,54 @@
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="10.1.2"></a>
6
+ ## [10.1.2](https://github.com/yargs/yargs/compare/v10.1.1...v10.1.2) (2018-01-17)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * requiresArg should only be enforced if argument exists ([#1043](https://github.com/yargs/yargs/issues/1043)) ([fbf41ae](https://github.com/yargs/yargs/commit/fbf41ae))
12
+
13
+
14
+
15
+ <a name="10.1.1"></a>
16
+ ## [10.1.1](https://github.com/yargs/yargs/compare/v10.1.0...v10.1.1) (2018-01-09)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * Add `dirname` sanity check on `findUp` ([#1036](https://github.com/yargs/yargs/issues/1036)) ([331d103](https://github.com/yargs/yargs/commit/331d103))
22
+
23
+
24
+
25
+ <a name="10.1.0"></a>
26
+ # [10.1.0](https://github.com/yargs/yargs/compare/v10.0.3...v10.1.0) (2018-01-01)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * '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))
32
+
33
+
34
+ ### Features
35
+
36
+ * add missing simple chinese locale strings ([#1004](https://github.com/yargs/yargs/issues/1004)) ([3cc24ec](https://github.com/yargs/yargs/commit/3cc24ec))
37
+ * add Norwegian Nynorsk translations ([#1028](https://github.com/yargs/yargs/issues/1028)) ([a5ac213](https://github.com/yargs/yargs/commit/a5ac213))
38
+ * async command handlers ([#1001](https://github.com/yargs/yargs/issues/1001)) ([241124b](https://github.com/yargs/yargs/commit/241124b))
39
+ * middleware ([#881](https://github.com/yargs/yargs/issues/881)) ([77b8dbc](https://github.com/yargs/yargs/commit/77b8dbc))
40
+
41
+
42
+
43
+ <a name="10.0.3"></a>
44
+ ## [10.0.3](https://github.com/yargs/yargs/compare/v10.0.2...v10.0.3) (2017-10-21)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * parse array rather than string, so that quotes are safe ([#993](https://github.com/yargs/yargs/issues/993)) ([c351685](https://github.com/yargs/yargs/commit/c351685))
50
+
51
+
52
+
5
53
  <a name="10.0.2"></a>
6
54
  ## [10.0.2](https://github.com/yargs/yargs/compare/v10.0.1...v10.0.2) (2017-10-21)
7
55
 
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) {
@@ -318,15 +331,16 @@ module.exports = function command (yargs, usage, validation) {
318
331
 
319
332
  const unparsed = []
320
333
  Object.keys(positionalMap).forEach((key) => {
321
- [].push.apply(unparsed, positionalMap[key].map((value) => {
322
- return `--${key} ${value}`
323
- }))
334
+ positionalMap[key].map((value) => {
335
+ unparsed.push(`--${key}`)
336
+ unparsed.push(value)
337
+ })
324
338
  })
325
339
 
326
340
  // short-circuit parse.
327
341
  if (!unparsed.length) return
328
342
 
329
- const parsed = Parser.detailed(unparsed.join(' '), options)
343
+ const parsed = Parser.detailed(unparsed, options)
330
344
 
331
345
  if (parsed.error) {
332
346
  yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
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
@@ -57,15 +57,17 @@ module.exports = function validation (yargs, usage, y18n) {
57
57
  // make sure that any args that require an
58
58
  // value (--foo=bar), have a value.
59
59
  self.missingArgumentValue = function missingArgumentValue (argv) {
60
- const defaultValues = [true, false, '']
60
+ const defaultValues = [true, false, '', undefined]
61
61
  const options = yargs.getOptions()
62
-
63
62
  if (options.requiresArg.length > 0) {
64
63
  const missingRequiredArgs = []
65
64
 
66
65
  options.requiresArg.forEach((key) => {
67
- const value = argv[key]
66
+ // if the argument is not set in argv no need to check
67
+ // whether a right-hand-side has been provided.
68
+ if (!argv.hasOwnProperty(key)) return
68
69
 
70
+ const value = argv[key]
69
71
  // if a value is explicitly requested,
70
72
  // flag argument as missing if it does not
71
73
  // look like foo=bar was entered.
@@ -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.2",
3
+ "version": "10.1.2",
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": "^8.1.0"
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
@@ -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))