yargs 11.0.0 → 11.1.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 +16 -0
- package/README.md +23 -11
- package/lib/apply-extends.js +4 -4
- package/lib/usage.js +17 -10
- package/package.json +2 -2
- package/yargs.js +43 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
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.1.0"></a>
|
|
6
|
+
# [11.1.0](https://github.com/yargs/yargs/compare/v11.0.0...v11.1.0) (2018-03-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* choose correct config directory when require.main does not exist ([#1056](https://github.com/yargs/yargs/issues/1056)) ([a04678c](https://github.com/yargs/yargs/commit/a04678c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* allow hidden options to be displayed with --show-hidden ([#1061](https://github.com/yargs/yargs/issues/1061)) ([ea862ae](https://github.com/yargs/yargs/commit/ea862ae))
|
|
17
|
+
* extend *.rc files in addition to json ([#1080](https://github.com/yargs/yargs/issues/1080)) ([11691a6](https://github.com/yargs/yargs/commit/11691a6))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
5
21
|
<a name="11.0.0"></a>
|
|
6
22
|
# [11.0.0](https://github.com/yargs/yargs/compare/v10.1.2...v11.0.0) (2018-01-22)
|
|
7
23
|
|
package/README.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width="250" src="/yargs-logo.png">
|
|
3
|
+
</p>
|
|
4
|
+
<h1 align="center"> Yargs </h1>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<b >Yargs be a node.js library fer hearties tryin' ter parse optstrings</b>
|
|
7
|
+
</p>
|
|
8
|
+
<br>
|
|
2
9
|
|
|
3
10
|
[![Build Status][travis-image]][travis-url]
|
|
4
11
|
[![Coverage Status][coveralls-image]][coveralls-url]
|
|
@@ -8,13 +15,10 @@
|
|
|
8
15
|
[![Conventional Commits][conventional-commits-image]][conventional-commits-url]
|
|
9
16
|
[![Slack][slack-image]][slack-url]
|
|
10
17
|
|
|
11
|
-
|
|
18
|
+
## Description :
|
|
19
|
+
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface.
|
|
12
20
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
<img width="250" src="/yargs-logo.png">
|
|
16
|
-
|
|
17
|
-
Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you:
|
|
21
|
+
It gives you:
|
|
18
22
|
|
|
19
23
|
* commands and (grouped) options (`my-program.js serve --port=5000`).
|
|
20
24
|
* a dynamically generated help menu based on your arguments.
|
|
@@ -30,7 +34,9 @@ Yargs helps you build interactive command line tools, by parsing arguments and g
|
|
|
30
34
|
npm i yargs --save
|
|
31
35
|
```
|
|
32
36
|
|
|
33
|
-
##
|
|
37
|
+
## Usage :
|
|
38
|
+
|
|
39
|
+
### Simple Example
|
|
34
40
|
|
|
35
41
|
````javascript
|
|
36
42
|
#!/usr/bin/env node
|
|
@@ -51,9 +57,9 @@ $ ./plunder.js --ships 12 --distance 98.7
|
|
|
51
57
|
Retreat from the xupptumblers!
|
|
52
58
|
```
|
|
53
59
|
|
|
54
|
-
|
|
60
|
+
### Complex Example
|
|
55
61
|
|
|
56
|
-
```
|
|
62
|
+
```javascript
|
|
57
63
|
#!/usr/bin/env node
|
|
58
64
|
require('yargs') // eslint-disable-line
|
|
59
65
|
.command('serve [port]', 'start the server', (yargs) => {
|
|
@@ -75,7 +81,13 @@ require('yargs') // eslint-disable-line
|
|
|
75
81
|
|
|
76
82
|
Run the example above with `--help` to see the help for the application.
|
|
77
83
|
|
|
78
|
-
##
|
|
84
|
+
## Community :
|
|
85
|
+
|
|
86
|
+
Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com).
|
|
87
|
+
|
|
88
|
+
## Documentation :
|
|
89
|
+
|
|
90
|
+
### Table of Contents
|
|
79
91
|
|
|
80
92
|
* [Yargs' API](/docs/api.md)
|
|
81
93
|
* [Examples](/docs/examples.md)
|
package/lib/apply-extends.js
CHANGED
|
@@ -6,9 +6,9 @@ const YError = require('./yerror')
|
|
|
6
6
|
|
|
7
7
|
let previouslyVisitedConfigs = []
|
|
8
8
|
|
|
9
|
-
function checkForCircularExtends (
|
|
10
|
-
if (previouslyVisitedConfigs.indexOf(
|
|
11
|
-
throw new YError(`Circular extended configurations: '${
|
|
9
|
+
function checkForCircularExtends (cfgPath) {
|
|
10
|
+
if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
|
|
11
|
+
throw new YError(`Circular extended configurations: '${cfgPath}'.`)
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -21,7 +21,7 @@ function applyExtends (config, cwd) {
|
|
|
21
21
|
|
|
22
22
|
if (config.hasOwnProperty('extends')) {
|
|
23
23
|
if (typeof config.extends !== 'string') return defaultConfig
|
|
24
|
-
const isPath = /\.json$/.test(config.extends)
|
|
24
|
+
const isPath = /\.json|\..*rc$/.test(config.extends)
|
|
25
25
|
let pathToDefault = null
|
|
26
26
|
if (!isPath) {
|
|
27
27
|
try {
|
package/lib/usage.js
CHANGED
|
@@ -152,16 +152,23 @@ module.exports = function usage (yargs, y18n) {
|
|
|
152
152
|
const demandedCommands = yargs.getDemandedCommands()
|
|
153
153
|
const groups = yargs.getGroups()
|
|
154
154
|
const options = yargs.getOptions()
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
155
|
+
|
|
156
|
+
let keys = []
|
|
157
|
+
keys = keys.concat(Object.keys(descriptions))
|
|
158
|
+
keys = keys.concat(Object.keys(demandedOptions))
|
|
159
|
+
keys = keys.concat(Object.keys(demandedCommands))
|
|
160
|
+
keys = keys.concat(Object.keys(options.default))
|
|
161
|
+
keys = keys.filter(key => {
|
|
162
|
+
if (options.hiddenOptions.indexOf(key) < 0) {
|
|
163
|
+
return true
|
|
164
|
+
} else if (yargs.parsed.argv[options.showHiddenOpt]) {
|
|
165
|
+
return true
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
keys = Object.keys(keys.reduce((acc, key) => {
|
|
169
|
+
if (key !== '_') acc[key] = true
|
|
170
|
+
return acc
|
|
171
|
+
}, {}))
|
|
165
172
|
|
|
166
173
|
const theWrap = getWrap()
|
|
167
174
|
const ui = require('cliui')({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.0",
|
|
4
4
|
"description": "yargs the modern, pirate-themed, successor to optimist.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"chalk": "^1.1.3",
|
|
31
31
|
"coveralls": "^2.11.11",
|
|
32
32
|
"cpr": "^2.0.0",
|
|
33
|
-
"cross-spawn": "^
|
|
33
|
+
"cross-spawn": "^6.0.4",
|
|
34
34
|
"es6-promise": "^4.0.2",
|
|
35
35
|
"hashish": "0.0.4",
|
|
36
36
|
"mocha": "^3.0.1",
|
package/yargs.js
CHANGED
|
@@ -93,7 +93,8 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
93
93
|
|
|
94
94
|
const arrayOptions = [
|
|
95
95
|
'array', 'boolean', 'string', 'skipValidation',
|
|
96
|
-
'count', 'normalize', 'number'
|
|
96
|
+
'count', 'normalize', 'number',
|
|
97
|
+
'hiddenOptions'
|
|
97
98
|
]
|
|
98
99
|
|
|
99
100
|
const objectOptions = [
|
|
@@ -476,17 +477,17 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
476
477
|
return self
|
|
477
478
|
}
|
|
478
479
|
|
|
479
|
-
self.pkgConf = function pkgConf (key,
|
|
480
|
-
argsert('<string> [string]', [key,
|
|
480
|
+
self.pkgConf = function pkgConf (key, rootPath) {
|
|
481
|
+
argsert('<string> [string]', [key, rootPath], arguments.length)
|
|
481
482
|
let conf = null
|
|
482
483
|
// prefer cwd to require-main-filename in this method
|
|
483
484
|
// since we're looking for e.g. "nyc" config in nyc consumer
|
|
484
485
|
// rather than "yargs" config in nyc (where nyc is the main filename)
|
|
485
|
-
const obj = pkgUp(
|
|
486
|
+
const obj = pkgUp(rootPath || cwd)
|
|
486
487
|
|
|
487
488
|
// If an object exists in the key, add it to options.configObjects
|
|
488
489
|
if (obj[key] && typeof obj[key] === 'object') {
|
|
489
|
-
conf = applyExtends(obj[key],
|
|
490
|
+
conf = applyExtends(obj[key], rootPath || cwd)
|
|
490
491
|
options.configObjects = (options.configObjects || []).concat(conf)
|
|
491
492
|
}
|
|
492
493
|
|
|
@@ -494,16 +495,24 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
494
495
|
}
|
|
495
496
|
|
|
496
497
|
const pkgs = {}
|
|
497
|
-
function pkgUp (
|
|
498
|
-
const npath =
|
|
498
|
+
function pkgUp (rootPath) {
|
|
499
|
+
const npath = rootPath || '*'
|
|
499
500
|
if (pkgs[npath]) return pkgs[npath]
|
|
500
501
|
const findUp = require('find-up')
|
|
501
502
|
|
|
502
503
|
let obj = {}
|
|
503
504
|
try {
|
|
505
|
+
let startDir = rootPath || require('require-main-filename')(parentRequire || require)
|
|
506
|
+
|
|
507
|
+
// When called in an environment that lacks require.main.filename, such as a jest test runner,
|
|
508
|
+
// startDir is already process.cwd(), and should not be shortened.
|
|
509
|
+
// Whether or not it is _actually_ a directory (e.g., extensionless bin) is irrelevant, find-up handles it.
|
|
510
|
+
if (!rootPath && path.extname(startDir)) {
|
|
511
|
+
startDir = path.dirname(startDir)
|
|
512
|
+
}
|
|
513
|
+
|
|
504
514
|
const pkgJsonPath = findUp.sync('package.json', {
|
|
505
|
-
cwd:
|
|
506
|
-
normalize: false
|
|
515
|
+
cwd: startDir
|
|
507
516
|
})
|
|
508
517
|
obj = JSON.parse(fs.readFileSync(pkgJsonPath))
|
|
509
518
|
} catch (noop) {}
|
|
@@ -649,8 +658,9 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
649
658
|
}
|
|
650
659
|
|
|
651
660
|
const desc = opt.describe || opt.description || opt.desc
|
|
652
|
-
|
|
653
|
-
|
|
661
|
+
self.describe(key, desc)
|
|
662
|
+
if (opt.hidden) {
|
|
663
|
+
self.hide(key)
|
|
654
664
|
}
|
|
655
665
|
|
|
656
666
|
if (opt.requiresArg) {
|
|
@@ -816,6 +826,28 @@ function Yargs (processArgs, cwd, parentRequire) {
|
|
|
816
826
|
return self
|
|
817
827
|
}
|
|
818
828
|
|
|
829
|
+
const defaultShowHiddenOpt = 'show-hidden'
|
|
830
|
+
options.showHiddenOpt = defaultShowHiddenOpt
|
|
831
|
+
self.addShowHiddenOpt = self.showHidden = function addShowHiddenOpt (opt, msg) {
|
|
832
|
+
argsert('[string|boolean] [string]', [opt, msg], arguments.length)
|
|
833
|
+
|
|
834
|
+
if (arguments.length === 1) {
|
|
835
|
+
if (opt === false) return self
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const showHiddenOpt = typeof opt === 'string' ? opt : defaultShowHiddenOpt
|
|
839
|
+
self.boolean(showHiddenOpt)
|
|
840
|
+
self.describe(showHiddenOpt, msg || usage.deferY18nLookup('Show hidden options'))
|
|
841
|
+
options.showHiddenOpt = showHiddenOpt
|
|
842
|
+
return self
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
self.hide = function hide (key) {
|
|
846
|
+
argsert('<string|object>', [key], arguments.length)
|
|
847
|
+
options.hiddenOptions.push(key)
|
|
848
|
+
return self
|
|
849
|
+
}
|
|
850
|
+
|
|
819
851
|
self.showHelpOnFail = function showHelpOnFail (enabled, message) {
|
|
820
852
|
argsert('[boolean|string] [string]', [enabled, message], arguments.length)
|
|
821
853
|
usage.showHelpOnFail(enabled, message)
|