yargs 4.8.0-candidate2 → 4.8.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 +36 -0
- package/README.md +2 -2
- package/lib/command.js +5 -13
- package/lib/validation.js +8 -2
- package/package.json +5 -4
- package/yargs.js +15 -10
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
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.8.1"></a>
|
|
6
|
+
## [4.8.1](https://github.com/yargs/yargs/compare/v4.8.0...v4.8.1) (2016-07-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **commandDir:** make dir relative to caller instead of require.main.filename ([#548](https://github.com/yargs/yargs/issues/548)) ([3c2e479](https://github.com/yargs/yargs/commit/3c2e479))
|
|
12
|
+
* add config lookup for .implies() ([#556](https://github.com/yargs/yargs/issues/556)) ([8d7585c](https://github.com/yargs/yargs/commit/8d7585c))
|
|
13
|
+
* cache pkg lookups by path to avoid returning the wrong one ([#552](https://github.com/yargs/yargs/issues/552)) ([fea7e0b](https://github.com/yargs/yargs/commit/fea7e0b))
|
|
14
|
+
* positional arguments were not being handled appropriately by parse() ([#559](https://github.com/yargs/yargs/issues/559)) ([063a866](https://github.com/yargs/yargs/commit/063a866))
|
|
15
|
+
* pull in [@nexdrew](https://github.com/nexdrew)'s fixes to yargs-parser ([#560](https://github.com/yargs/yargs/issues/560)) ([c77c080](https://github.com/yargs/yargs/commit/c77c080)), closes [#560](https://github.com/yargs/yargs/issues/560)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<a name="4.8.0"></a>
|
|
20
|
+
# [4.8.0](https://github.com/yargs/yargs/compare/v4.7.1...v4.8.0) (2016-07-09)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
* drop unused camelcase dependency fixes [#516](https://github.com/yargs/yargs/issues/516) ([#525](https://github.com/yargs/yargs/issues/525)) ([365fb9a](https://github.com/yargs/yargs/commit/365fb9a)), closes [#516](https://github.com/yargs/yargs/issues/516) [#525](https://github.com/yargs/yargs/issues/525)
|
|
26
|
+
* fake a tty in tests, so that we can use the new set-blocking ([#512](https://github.com/yargs/yargs/issues/512)) ([a54c742](https://github.com/yargs/yargs/commit/a54c742))
|
|
27
|
+
* ignore invalid package.json during read-pkg-up ([#546](https://github.com/yargs/yargs/issues/546)) ([e058c87](https://github.com/yargs/yargs/commit/e058c87))
|
|
28
|
+
* keep both zh and zh_CN until yargs[@5](https://github.com/5).x ([0f8faa7](https://github.com/yargs/yargs/commit/0f8faa7))
|
|
29
|
+
* lazy-load package.json and cache. get rid of pkg-conf dependency. ([#544](https://github.com/yargs/yargs/issues/544)) ([2609b2e](https://github.com/yargs/yargs/commit/2609b2e))
|
|
30
|
+
* we now respect the order of _ when applying commands ([#537](https://github.com/yargs/yargs/issues/537)) ([ed86b78](https://github.com/yargs/yargs/commit/ed86b78))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* add .commandDir(dir) to API to apply all command modules from a relative directory ([#494](https://github.com/yargs/yargs/issues/494)) ([b299dff](https://github.com/yargs/yargs/commit/b299dff))
|
|
36
|
+
* **command:** derive missing command string from module filename ([#527](https://github.com/yargs/yargs/issues/527)) ([20d4b8a](https://github.com/yargs/yargs/commit/20d4b8a))
|
|
37
|
+
* builder is now optional for a command module ([#545](https://github.com/yargs/yargs/issues/545)) ([8d6ad6e](https://github.com/yargs/yargs/commit/8d6ad6e))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
5
41
|
<a name="4.7.1"></a>
|
|
6
42
|
## [4.7.1](https://github.com/yargs/yargs/compare/v4.7.0...v4.7.1) (2016-05-15)
|
|
7
43
|
|
package/README.md
CHANGED
|
@@ -1666,8 +1666,8 @@ This module is loosely inspired by Perl's
|
|
|
1666
1666
|
[coveralls-image]: https://img.shields.io/coveralls/yargs/yargs.svg
|
|
1667
1667
|
[npm-url]: https://www.npmjs.com/package/yargs
|
|
1668
1668
|
[npm-image]: https://img.shields.io/npm/v/yargs.svg
|
|
1669
|
-
[windows-url]: https://ci.appveyor.com/project/bcoe/yargs
|
|
1670
|
-
[windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs/master.svg?label=Windows%20Tests
|
|
1669
|
+
[windows-url]: https://ci.appveyor.com/project/bcoe/yargs-ljwvf
|
|
1670
|
+
[windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs-ljwvf/master.svg?label=Windows%20Tests
|
|
1671
1671
|
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
|
|
1672
1672
|
[standard-url]: http://standardjs.com/
|
|
1673
1673
|
[standard-version-image]: https://img.shields.io/badge/release-standard%20version-brightgreen.svg
|
package/lib/command.js
CHANGED
|
@@ -11,14 +11,9 @@ module.exports = function (yargs, usage, validation) {
|
|
|
11
11
|
|
|
12
12
|
var handlers = {}
|
|
13
13
|
self.addHandler = function (cmd, description, builder, handler) {
|
|
14
|
-
// allow modules that define (a) all properties or (b) only command and description
|
|
15
14
|
if (typeof cmd === 'object') {
|
|
16
15
|
const commandString = typeof cmd.command === 'string' ? cmd.command : moduleName(cmd)
|
|
17
|
-
|
|
18
|
-
self.addHandler(commandString, extractDesc(cmd), cmd.builder, cmd.handler)
|
|
19
|
-
} else {
|
|
20
|
-
self.addHandler(commandString, extractDesc(cmd))
|
|
21
|
-
}
|
|
16
|
+
self.addHandler(commandString, extractDesc(cmd), cmd.builder, cmd.handler)
|
|
22
17
|
return
|
|
23
18
|
}
|
|
24
19
|
|
|
@@ -39,16 +34,16 @@ module.exports = function (yargs, usage, validation) {
|
|
|
39
34
|
handlers[parsedCommand.cmd] = {
|
|
40
35
|
original: cmd,
|
|
41
36
|
handler: handler,
|
|
37
|
+
// TODO: default to a noop builder in
|
|
38
|
+
// yargs@5.x
|
|
42
39
|
builder: builder,
|
|
43
40
|
demanded: parsedCommand.demanded,
|
|
44
41
|
optional: parsedCommand.optional
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
|
|
48
|
-
self.addDirectory = function (dir, context, req,
|
|
45
|
+
self.addDirectory = function (dir, context, req, callerFile, opts) {
|
|
49
46
|
opts = opts || {}
|
|
50
|
-
// dir should be relative to the command module
|
|
51
|
-
dir = path.join(context.dirs[context.commands.join('|')] || '', dir)
|
|
52
47
|
// disable recursion to support nested directories of subcommands
|
|
53
48
|
if (typeof opts.recurse !== 'boolean') opts.recurse = false
|
|
54
49
|
// exclude 'json', 'coffee' from require-directory defaults
|
|
@@ -65,14 +60,11 @@ module.exports = function (yargs, usage, validation) {
|
|
|
65
60
|
if (~context.files.indexOf(joined)) return visited
|
|
66
61
|
// keep track of visited files in context.files
|
|
67
62
|
context.files.push(joined)
|
|
68
|
-
// map "command path" to the directory path it came from
|
|
69
|
-
// so that dir can be relative in the API
|
|
70
|
-
context.dirs[context.commands.concat(parseCommand(visited.command || commandFromFilename(filename)).cmd).join('|')] = dir
|
|
71
63
|
self.addHandler(visited)
|
|
72
64
|
}
|
|
73
65
|
return visited
|
|
74
66
|
}
|
|
75
|
-
requireDirectory({ require: req, filename:
|
|
67
|
+
requireDirectory({ require: req, filename: callerFile }, dir, opts)
|
|
76
68
|
}
|
|
77
69
|
|
|
78
70
|
// lookup module object from require()d command and derive name
|
package/lib/validation.js
CHANGED
|
@@ -219,6 +219,12 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
219
219
|
const implyFail = []
|
|
220
220
|
|
|
221
221
|
Object.keys(implied).forEach(function (key) {
|
|
222
|
+
var booleanNegation
|
|
223
|
+
if (yargs.getOptions().configuration['boolean-negation'] === false) {
|
|
224
|
+
booleanNegation = false
|
|
225
|
+
} else {
|
|
226
|
+
booleanNegation = true
|
|
227
|
+
}
|
|
222
228
|
var num
|
|
223
229
|
const origKey = key
|
|
224
230
|
var value = implied[key]
|
|
@@ -230,7 +236,7 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
230
236
|
if (typeof key === 'number') {
|
|
231
237
|
// check length of argv._
|
|
232
238
|
key = argv._.length >= key
|
|
233
|
-
} else if (key.match(/^--no-.+/)) {
|
|
239
|
+
} else if (key.match(/^--no-.+/) && booleanNegation) {
|
|
234
240
|
// check if key doesn't exist
|
|
235
241
|
key = key.match(/^--no-(.+)/)[1]
|
|
236
242
|
key = !argv[key]
|
|
@@ -244,7 +250,7 @@ module.exports = function (yargs, usage, y18n) {
|
|
|
244
250
|
|
|
245
251
|
if (typeof value === 'number') {
|
|
246
252
|
value = argv._.length >= value
|
|
247
|
-
} else if (value.match(/^--no-.+/)) {
|
|
253
|
+
} else if (value.match(/^--no-.+/) && booleanNegation) {
|
|
248
254
|
value = value.match(/^--no-(.+)/)[1]
|
|
249
255
|
value = !argv[value]
|
|
250
256
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"cliui": "^3.2.0",
|
|
16
16
|
"decamelize": "^1.1.1",
|
|
17
|
+
"get-caller-file": "^1.0.1",
|
|
17
18
|
"lodash.assign": "^4.0.3",
|
|
18
19
|
"os-locale": "^1.4.0",
|
|
19
20
|
"read-pkg-up": "^1.0.1",
|
|
@@ -24,14 +25,14 @@
|
|
|
24
25
|
"which-module": "^1.0.0",
|
|
25
26
|
"window-size": "^0.2.0",
|
|
26
27
|
"y18n": "^3.2.1",
|
|
27
|
-
"yargs-parser": "^2.4.
|
|
28
|
+
"yargs-parser": "^2.4.1"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
31
|
"chai": "^3.4.1",
|
|
31
32
|
"chalk": "^1.1.3",
|
|
32
|
-
"coveralls": "^2.11.
|
|
33
|
+
"coveralls": "^2.11.11",
|
|
33
34
|
"cpr": "^1.0.0",
|
|
34
|
-
"cross-spawn
|
|
35
|
+
"cross-spawn": "^4.0.0",
|
|
35
36
|
"es6-promise": "^3.0.2",
|
|
36
37
|
"hashish": "0.0.4",
|
|
37
38
|
"mocha": "^2.5.2",
|
package/yargs.js
CHANGED
|
@@ -49,7 +49,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
49
49
|
|
|
50
50
|
// use context object to keep track of resets, subcommand execution, etc
|
|
51
51
|
// submodules should modify and check the state of context as necessary
|
|
52
|
-
const context = { resets: -1, commands: [],
|
|
52
|
+
const context = { resets: -1, commands: [], files: [] }
|
|
53
53
|
self.getContext = function () {
|
|
54
54
|
return context
|
|
55
55
|
}
|
|
@@ -207,7 +207,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
207
207
|
|
|
208
208
|
self.commandDir = function (dir, opts) {
|
|
209
209
|
const req = parentRequire || require
|
|
210
|
-
command.addDirectory(dir, self.getContext(), req,
|
|
210
|
+
command.addDirectory(dir, self.getContext(), req, require('get-caller-file')(), opts)
|
|
211
211
|
return self
|
|
212
212
|
}
|
|
213
213
|
|
|
@@ -355,20 +355,25 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
355
355
|
return self
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
var
|
|
358
|
+
var pkgs = {}
|
|
359
359
|
function pkgUp (path) {
|
|
360
|
-
|
|
360
|
+
var npath = path || '*'
|
|
361
|
+
if (pkgs[npath]) return pkgs[npath]
|
|
361
362
|
const readPkgUp = require('read-pkg-up')
|
|
362
363
|
|
|
363
|
-
var obj =
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
var obj = {}
|
|
365
|
+
try {
|
|
366
|
+
obj = readPkgUp.sync({
|
|
367
|
+
cwd: path || requireMainFilename(parentRequire || require)
|
|
368
|
+
})
|
|
369
|
+
} catch (noop) {}
|
|
366
370
|
|
|
367
|
-
|
|
368
|
-
return
|
|
371
|
+
pkgs[npath] = obj.pkg || {}
|
|
372
|
+
return pkgs[npath]
|
|
369
373
|
}
|
|
370
374
|
|
|
371
375
|
self.parse = function (args, shortCircuit) {
|
|
376
|
+
if (!shortCircuit) processArgs = args
|
|
372
377
|
return parseArgs(args, shortCircuit)
|
|
373
378
|
}
|
|
374
379
|
|
|
@@ -632,7 +637,7 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
632
637
|
|
|
633
638
|
function parseArgs (args, shortCircuit) {
|
|
634
639
|
options.__ = y18n.__
|
|
635
|
-
options.configuration = pkgUp()['yargs'] || {}
|
|
640
|
+
options.configuration = pkgUp(cwd)['yargs'] || {}
|
|
636
641
|
const parsed = Parser.detailed(args, options)
|
|
637
642
|
const argv = parsed.argv
|
|
638
643
|
var aliases = parsed.aliases
|