yargs 4.7.0 → 4.7.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,17 @@
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="4.7.1"></a>
6
+ ## [4.7.1](https://github.com/yargs/yargs/compare/v4.7.0...v4.7.1) (2016-05-15)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * switch to using `const` rather than `var` ([#499](https://github.com/yargs/yargs/pull/499))
12
+ * make stdout flush on newer versions of Node.js ([#501](https://github.com/yargs/yargs/issues/501)) ([9f8c6f4](https://github.com/yargs/yargs/commit/9f8c6f4))
13
+
14
+
15
+
5
16
  <a name="4.7.0"></a>
6
17
  # [4.7.0](https://github.com/yargs/yargs/compare/v4.6.0...v4.7.0) (2016-05-02)
7
18
 
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  // classic singleton yargs API, to use yargs
2
2
  // without running as a singleton do:
3
3
  // require('yargs/yargs')(process.argv.slice(2))
4
- var yargs = require('./yargs')
4
+ const yargs = require('./yargs')
5
5
 
6
6
  Argv(process.argv.slice(2))
7
7
 
8
8
  module.exports = Argv
9
9
 
10
10
  function Argv (processArgs, cwd) {
11
- var argv = yargs(processArgs, cwd, require)
11
+ const argv = yargs(processArgs, cwd, require)
12
12
  singletonify(argv)
13
13
  return argv
14
14
  }
package/lib/command.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // and populating argv with said positional
3
3
  // arguments.
4
4
  module.exports = function (yargs, usage, validation) {
5
- var self = {}
5
+ const self = {}
6
6
 
7
7
  var handlers = {}
8
8
  self.addHandler = function (cmd, description, builder, handler) {
package/lib/completion.js CHANGED
@@ -1,20 +1,20 @@
1
- var fs = require('fs')
2
- var path = require('path')
1
+ const fs = require('fs')
2
+ const path = require('path')
3
3
 
4
4
  // add bash completions to your
5
5
  // yargs-powered applications.
6
6
  module.exports = function (yargs, usage, command) {
7
- var self = {
7
+ const self = {
8
8
  completionKey: 'get-yargs-completions'
9
9
  }
10
10
 
11
11
  // get a list of completion commands.
12
12
  // 'args' is the array of strings from the line to be completed
13
13
  self.getCompletion = function (args, done) {
14
- var completions = []
15
- var current = args.length ? args[args.length - 1] : ''
16
- var argv = yargs.parse(args, true)
17
- var aliases = yargs.parsed.aliases
14
+ const completions = []
15
+ const current = args.length ? args[args.length - 1] : ''
16
+ const argv = yargs.parse(args, true)
17
+ const aliases = yargs.parsed.aliases
18
18
 
19
19
  // a custom completion function can be provided
20
20
  // to completion().
package/lib/obj-filter.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = function (original, filter) {
2
- var obj = {}
2
+ const obj = {}
3
3
  filter = filter || function (k, v) { return true }
4
4
  Object.keys(original || {}).forEach(function (key) {
5
5
  if (filter(key, original[key])) {
package/lib/usage.js CHANGED
@@ -1,14 +1,15 @@
1
1
  // this file handles outputting usage instructions,
2
2
  // failures, etc. keeps logging in one place.
3
- var cliui = require('cliui')
4
- var decamelize = require('decamelize')
5
- var stringWidth = require('string-width')
6
- var wsize = require('window-size')
7
- var objFilter = require('./obj-filter')
3
+ const cliui = require('cliui')
4
+ const decamelize = require('decamelize')
5
+ const stringWidth = require('string-width')
6
+ const wsize = require('window-size')
7
+ const objFilter = require('./obj-filter')
8
+ const setBlocking = require('set-blocking')
8
9
 
9
10
  module.exports = function (yargs, y18n) {
10
- var __ = y18n.__
11
- var self = {}
11
+ const __ = y18n.__
12
+ const self = {}
12
13
 
13
14
  // methods for ouputting/building failure message.
14
15
  var fails = []
@@ -37,6 +38,8 @@ module.exports = function (yargs, y18n) {
37
38
  f(msg, err)
38
39
  })
39
40
  } else {
41
+ if (yargs.getExitProcess()) setBlocking(true)
42
+
40
43
  // don't output failure message more than once
41
44
  if (!failureOutput) {
42
45
  failureOutput = true
package/lib/validation.js CHANGED
@@ -1,17 +1,17 @@
1
- var objFilter = require('./obj-filter')
1
+ const objFilter = require('./obj-filter')
2
2
 
3
3
  // validation-type-stuff, missing params,
4
4
  // bad implications, custom checks.
5
5
  module.exports = function (yargs, usage, y18n) {
6
- var __ = y18n.__
7
- var __n = y18n.__n
8
- var self = {}
6
+ const __ = y18n.__
7
+ const __n = y18n.__n
8
+ const self = {}
9
9
 
10
10
  // validate appropriate # of non-option
11
11
  // arguments were provided, i.e., '_'.
12
12
  self.nonOptionCount = function (argv) {
13
- var demanded = yargs.getDemanded()
14
- var _s = argv._.length
13
+ const demanded = yargs.getDemanded()
14
+ const _s = argv._.length
15
15
 
16
16
  if (demanded._ && (_s < demanded._.count || _s > demanded._.max)) {
17
17
  if (demanded._.msg !== undefined) {
@@ -41,14 +41,14 @@ module.exports = function (yargs, usage, y18n) {
41
41
  // make sure that any args that require an
42
42
  // value (--foo=bar), have a value.
43
43
  self.missingArgumentValue = function (argv) {
44
- var defaultValues = [true, false, '']
45
- var options = yargs.getOptions()
44
+ const defaultValues = [true, false, '']
45
+ const options = yargs.getOptions()
46
46
 
47
47
  if (options.requiresArg.length > 0) {
48
- var missingRequiredArgs = []
48
+ const missingRequiredArgs = []
49
49
 
50
50
  options.requiresArg.forEach(function (key) {
51
- var value = argv[key]
51
+ const value = argv[key]
52
52
 
53
53
  // if a value is explicitly requested,
54
54
  // flag argument as missing if it does not
@@ -72,7 +72,7 @@ module.exports = function (yargs, usage, y18n) {
72
72
 
73
73
  // make sure all the required arguments are present.
74
74
  self.requiredArguments = function (argv) {
75
- var demanded = yargs.getDemanded()
75
+ const demanded = yargs.getDemanded()
76
76
  var missing = null
77
77
 
78
78
  Object.keys(demanded).forEach(function (key) {
@@ -83,15 +83,15 @@ module.exports = function (yargs, usage, y18n) {
83
83
  })
84
84
 
85
85
  if (missing) {
86
- var customMsgs = []
86
+ const customMsgs = []
87
87
  Object.keys(missing).forEach(function (key) {
88
- var msg = missing[key].msg
88
+ const msg = missing[key].msg
89
89
  if (msg && customMsgs.indexOf(msg) < 0) {
90
90
  customMsgs.push(msg)
91
91
  }
92
92
  })
93
93
 
94
- var customMsg = customMsgs.length ? '\n' + customMsgs.join('\n') : ''
94
+ const customMsg = customMsgs.length ? '\n' + customMsgs.join('\n') : ''
95
95
 
96
96
  usage.fail(__n(
97
97
  'Missing required argument: %s',
@@ -104,12 +104,12 @@ module.exports = function (yargs, usage, y18n) {
104
104
 
105
105
  // check for unknown arguments (strict-mode).
106
106
  self.unknownArguments = function (argv, aliases) {
107
- var aliasLookup = {}
108
- var descriptions = usage.getDescriptions()
109
- var demanded = yargs.getDemanded()
110
- var commandKeys = yargs.getCommandInstance().getCommands()
111
- var unknown = []
112
- var currentContext = yargs.getContext()
107
+ const aliasLookup = {}
108
+ const descriptions = usage.getDescriptions()
109
+ const demanded = yargs.getDemanded()
110
+ const commandKeys = yargs.getCommandInstance().getCommands()
111
+ const unknown = []
112
+ const currentContext = yargs.getContext()
113
113
 
114
114
  Object.keys(aliases).forEach(function (key) {
115
115
  aliases[key].forEach(function (alias) {
@@ -146,8 +146,8 @@ module.exports = function (yargs, usage, y18n) {
146
146
 
147
147
  // validate arguments limited to enumerated choices
148
148
  self.limitedChoices = function (argv) {
149
- var options = yargs.getOptions()
150
- var invalid = {}
149
+ const options = yargs.getOptions()
150
+ const invalid = {}
151
151
 
152
152
  if (!Object.keys(options.choices).length) return
153
153
 
@@ -163,7 +163,7 @@ module.exports = function (yargs, usage, y18n) {
163
163
  }
164
164
  })
165
165
 
166
- var invalidKeys = Object.keys(invalid)
166
+ const invalidKeys = Object.keys(invalid)
167
167
 
168
168
  if (!invalidKeys.length) return
169
169
 
@@ -188,7 +188,7 @@ module.exports = function (yargs, usage, y18n) {
188
188
  self.customChecks = function (argv, aliases) {
189
189
  checks.forEach(function (f) {
190
190
  try {
191
- var result = f(argv, aliases)
191
+ const result = f(argv, aliases)
192
192
  if (!result) {
193
193
  usage.fail(__('Argument check failed: %s', f.toString()))
194
194
  } else if (typeof result === 'string') {
@@ -216,11 +216,11 @@ module.exports = function (yargs, usage, y18n) {
216
216
  }
217
217
 
218
218
  self.implications = function (argv) {
219
- var implyFail = []
219
+ const implyFail = []
220
220
 
221
221
  Object.keys(implied).forEach(function (key) {
222
222
  var num
223
- var origKey = key
223
+ const origKey = key
224
224
  var value = implied[key]
225
225
 
226
226
  // convert string '1' to number 1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yargs",
3
- "version": "4.7.0",
3
+ "version": "4.7.1",
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
- "camelcase": "^2.0.1",
15
+ "camelcase": "^3.0.0",
16
16
  "cliui": "^3.2.0",
17
17
  "decamelize": "^1.1.1",
18
18
  "lodash.assign": "^4.0.3",
@@ -20,6 +20,7 @@
20
20
  "pkg-conf": "^1.1.2",
21
21
  "read-pkg-up": "^1.0.1",
22
22
  "require-main-filename": "^1.0.1",
23
+ "set-blocking": "^1.0.0",
23
24
  "string-width": "^1.0.1",
24
25
  "window-size": "^0.2.0",
25
26
  "y18n": "^3.2.1",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "scripts": {
44
45
  "pretest": "standard",
45
- "test": "nyc --cache mocha --require ./test/before.js --timeout=4000 --check-leaks",
46
+ "test": "nyc --cache mocha --require ./test/before.js --timeout=8000 --check-leaks",
46
47
  "coverage": "nyc report --reporter=text-lcov | coveralls",
47
48
  "version": "standard-version"
48
49
  },
package/yargs.js CHANGED
@@ -1,29 +1,30 @@
1
- var assert = require('assert')
2
- var assign = require('lodash.assign')
3
- var Command = require('./lib/command')
4
- var Completion = require('./lib/completion')
5
- var Parser = require('yargs-parser')
6
- var path = require('path')
7
- var Usage = require('./lib/usage')
8
- var Validation = require('./lib/validation')
9
- var Y18n = require('y18n')
10
- var readPkgUp = require('read-pkg-up')
11
- var pkgConf = require('pkg-conf')
12
- var requireMainFilename = require('require-main-filename')
13
- var objFilter = require('./lib/obj-filter')
1
+ const assert = require('assert')
2
+ const assign = require('lodash.assign')
3
+ const Command = require('./lib/command')
4
+ const Completion = require('./lib/completion')
5
+ const Parser = require('yargs-parser')
6
+ const path = require('path')
7
+ const Usage = require('./lib/usage')
8
+ const Validation = require('./lib/validation')
9
+ const Y18n = require('y18n')
10
+ const readPkgUp = require('read-pkg-up')
11
+ const pkgConf = require('pkg-conf')
12
+ const requireMainFilename = require('require-main-filename')
13
+ const objFilter = require('./lib/obj-filter')
14
+ const setBlocking = require('set-blocking')
14
15
 
15
16
  var exports = module.exports = Yargs
16
17
  function Yargs (processArgs, cwd, parentRequire) {
17
18
  processArgs = processArgs || [] // handle calling yargs().
18
19
 
19
- var self = {}
20
+ const self = {}
20
21
  var command = null
21
22
  var completion = null
22
23
  var groups = {}
23
24
  var preservedGroups = {}
24
25
  var usage = null
25
26
  var validation = null
26
- var y18n = Y18n({
27
+ const y18n = Y18n({
27
28
  directory: path.resolve(__dirname, './locales'),
28
29
  updateFiles: false
29
30
  })
@@ -49,7 +50,7 @@ function Yargs (processArgs, cwd, parentRequire) {
49
50
 
50
51
  // use context object to keep track of resets, subcommand execution, etc
51
52
  // submodules should modify and check the state of context as necessary
52
- var context = { resets: -1, commands: [] }
53
+ const context = { resets: -1, commands: [] }
53
54
  self.getContext = function () {
54
55
  return context
55
56
  }
@@ -621,8 +622,8 @@ function Yargs (processArgs, cwd, parentRequire) {
621
622
  defaults: {},
622
623
  cwd: requireMainFilename(require)
623
624
  })
624
- var parsed = Parser.detailed(args, options)
625
- var argv = parsed.argv
625
+ const parsed = Parser.detailed(args, options)
626
+ const argv = parsed.argv
626
627
  var aliases = parsed.aliases
627
628
 
628
629
  argv.$0 = self.$0
@@ -649,6 +650,7 @@ function Yargs (processArgs, cwd, parentRequire) {
649
650
 
650
651
  // generate a completion script for adding to ~/.bashrc.
651
652
  if (completionCommand && ~argv._.indexOf(completionCommand) && !argv[completion.completionKey]) {
653
+ if (exitProcess) setBlocking(true)
652
654
  self.showCompletionScript()
653
655
  if (exitProcess) {
654
656
  process.exit(0)
@@ -658,6 +660,8 @@ function Yargs (processArgs, cwd, parentRequire) {
658
660
  // we must run completions first, a user might
659
661
  // want to complete the --help or --version option.
660
662
  if (completion.completionKey in argv) {
663
+ if (exitProcess) setBlocking(true)
664
+
661
665
  // we allow for asynchronous completions,
662
666
  // e.g., loading in a list of commands from an API.
663
667
  var completionArgs = args.slice(args.indexOf('--' + completion.completionKey) + 1)
@@ -678,12 +682,16 @@ function Yargs (processArgs, cwd, parentRequire) {
678
682
  // Handle 'help' and 'version' options
679
683
  Object.keys(argv).forEach(function (key) {
680
684
  if (key === helpOpt && argv[key]) {
685
+ if (exitProcess) setBlocking(true)
686
+
681
687
  skipValidation = true
682
688
  self.showHelp('log')
683
689
  if (exitProcess) {
684
690
  process.exit(0)
685
691
  }
686
692
  } else if (key === versionOpt && argv[key]) {
693
+ if (exitProcess) setBlocking(true)
694
+
687
695
  skipValidation = true
688
696
  usage.showVersion()
689
697
  if (exitProcess) {
@@ -726,7 +734,7 @@ function Yargs (processArgs, cwd, parentRequire) {
726
734
  if (!detectLocale) return
727
735
 
728
736
  try {
729
- var osLocale = require('os-locale')
737
+ const osLocale = require('os-locale')
730
738
  self.locale(osLocale.sync({ spawn: false }))
731
739
  } catch (err) {
732
740
  // if we explode looking up locale just noop