Add posibility to pass a yargs instance to argv() method
This commit is contained in:
parent
856fdf8dff
commit
3e26bb2756
2 changed files with 26 additions and 3 deletions
17
README.md
17
README.md
|
@ -240,6 +240,23 @@ If the return value is falsey, the entry will be dropped from the store, otherwi
|
|||
});
|
||||
```
|
||||
|
||||
It's also possible to pass a configured yargs instance
|
||||
|
||||
``` js
|
||||
nconf.argv(require('yargs')
|
||||
.version('1.2.3')
|
||||
.usage('My usage definition')
|
||||
.strict()
|
||||
.options({
|
||||
"x": {
|
||||
alias: 'example',
|
||||
describe: 'Example description for usage generation',
|
||||
demand: true,
|
||||
default: 'some-value'
|
||||
}
|
||||
}));
|
||||
```
|
||||
|
||||
### Env
|
||||
Responsible for loading the values parsed from `process.env` into the configuration hierarchy.
|
||||
By default, the env variables values are loaded into the configuration as strings.
|
||||
|
|
|
@ -48,9 +48,11 @@ Argv.prototype.loadArgv = function () {
|
|||
var self = this,
|
||||
yargs, argv;
|
||||
|
||||
yargs = typeof this.options === 'object'
|
||||
? require('yargs')(process.argv.slice(2)).options(this.options)
|
||||
: require('yargs')(process.argv.slice(2));
|
||||
yargs = isYargs(this.options) ?
|
||||
this.options :
|
||||
typeof this.options === 'object' ?
|
||||
require('yargs')(process.argv.slice(2)).options(this.options) :
|
||||
require('yargs')(process.argv.slice(2));
|
||||
|
||||
if (typeof this.usage === 'string') { yargs.usage(this.usage) }
|
||||
|
||||
|
@ -83,3 +85,7 @@ Argv.prototype.loadArgv = function () {
|
|||
this.readOnly = true;
|
||||
return this.store;
|
||||
};
|
||||
|
||||
function isYargs(obj) {
|
||||
return (typeof obj === 'function') && ('argv' in obj);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue