Merge pull request #168 from ChristianMurphy/replace-optimist-with-yargs

Replace optimist with yargs
This commit is contained in:
Jarrett Cruger 2015-07-12 19:34:18 -04:00
commit 8afdf63497
9 changed files with 97 additions and 98 deletions

View file

@ -61,7 +61,7 @@ The output will be:
Configuration management can get complicated very quickly for even trivial applications running in production. `nconf` addresses this problem by enabling you to setup a hierarchy for different sources of configuration with no defaults. **The order in which you attach these configuration sources determines their priority in the hierarchy.** Lets take a look at the options available to you
1. **nconf.argv(options)** Loads `process.argv` using optimist. If `options` is supplied it is passed along to optimist.
1. **nconf.argv(options)** Loads `process.argv` using yargs. If `options` is supplied it is passed along to yargs.
2. **nconf.env(options)** Loads `process.env` into the hierarchy.
3. **nconf.file(options)** Loads the configuration data at options.file into the hierarchy.
4. **nconf.defaults(options)** Loads the data in options.store into the hierarchy.
@ -159,11 +159,11 @@ A simple in-memory storage engine that stores a nested JSON representation of th
```
### Argv
Responsible for loading the values parsed from `process.argv` by `optimist` into the configuration hierarchy. See the [optimist option docs](https://github.com/substack/node-optimist/#optionskey-opt) for more on the option format.
Responsible for loading the values parsed from `process.argv` by `yargs` into the configuration hierarchy. See the [yargs option docs](https://github.com/bcoe/yargs#optionskey-opt) for more on the option format.
``` js
//
// Can optionally also be an object literal to pass to `optimist`.
// Can optionally also be an object literal to pass to `yargs`.
//
nconf.argv({
"x": {

View file

@ -348,8 +348,8 @@ other values for this instance.</p> </td> <td class="cod
<span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;overrides&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_argv</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <h3>@argv {boolean}</h3>
<p>Gets or sets a property indicating if we should wrap calls to <code>.get</code>
by checking <code>optimist.argv</code>. Can be a boolean or the pass-thru
options for <code>optimist</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span> <span class="nx">updateSystem</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">});</span>
by checking <code>yargs.argv</code>. Can be a boolean or the pass-thru
options for <code>yargs</code>.</p> </td> <td class="code"> <div class="highlight"><pre><span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineSetter__</span><span class="p">(</span><span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">val</span><span class="p">)</span> <span class="p">{</span> <span class="nx">updateSystem</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="nx">val</span><span class="p">)</span> <span class="p">});</span>
<span class="nx">Provider</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">__defineGetter__</span><span class="p">(</span><span class="s1">&#39;argv&#39;</span><span class="p">,</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">_argv</span> <span class="p">});</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <h3>@env {boolean}</h3>
<p>Gets or sets a property indicating if we should wrap calls to <code>.get</code>

View file

@ -62,10 +62,10 @@ into this instance.</p> </td> <td class="code">
<span class="nx">argv</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="k">this</span><span class="p">.</span><span class="nx">argv</span> <span class="o">===</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;optimist&#39;</span><span class="p">).</span><span class="nx">options</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;yargs&#39;</span><span class="p">).</span><span class="nx">options</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">argv</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;optimist&#39;</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="nx">argv</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;yargs&#39;</span><span class="p">).</span><span class="nx">argv</span><span class="p">;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">argv</span><span class="p">)</span> <span class="p">{</span>

View file

@ -42,15 +42,15 @@ Argv.prototype.loadSync = function () {
//
Argv.prototype.loadArgv = function () {
var self = this,
optimist, argv;
yargs, argv;
optimist = typeof this.options === 'object'
? require('optimist')(process.argv.slice(2)).options(this.options)
: require('optimist')(process.argv.slice(2));
yargs = typeof this.options === 'object'
? require('yargs')(process.argv.slice(2)).options(this.options)
: require('yargs')(process.argv.slice(2));
if (typeof this.usage === 'string') { optimist.usage(this.usage) }
if (typeof this.usage === 'string') { yargs.usage(this.usage) }
argv = optimist.argv
argv = yargs.argv
if (!argv) {
return;
@ -61,8 +61,8 @@ Argv.prototype.loadArgv = function () {
self.set(key, argv[key]);
});
this.showHelp = optimist.showHelp
this.help = optimist.help
this.showHelp = yargs.showHelp
this.help = yargs.help
this.readOnly = true;
return this.store;

View file

@ -15,7 +15,7 @@
"dependencies": {
"async": "~0.9.0",
"ini": "1.x.x",
"optimist": "~0.6.0"
"yargs": "~3.15.0"
},
"devDependencies": {
"vows": "0.8.x"
@ -28,4 +28,3 @@
"node": ">= 0.4.0"
}
}

View file

@ -1,5 +1,5 @@
/*
* default-argv.js: Test fixture for using optimist defaults with nconf.
* default-argv.js: Test fixture for using yargs defaults with nconf.
*
* (C) 2011, Charlie Robbins and the Contributors.
*

View file

@ -1,5 +1,5 @@
/*
* nconf-hierarchical-file-argv.js: Test fixture for using optimist defaults and a file store with nconf.
* nconf-hierarchical-file-argv.js: Test fixture for using yargs defaults and a file store with nconf.
*
* (C) 2011, Charlie Robbins and the Contributors.
* (C) 2011, Sander Tolsma

View file

@ -1,5 +1,5 @@
/*
* nconf-hierarchical-load-save.js: Test fixture for using optimist, envvars and a file store with nconf.
* nconf-hierarchical-load-save.js: Test fixture for using yargs, envvars and a file store with nconf.
*
* (C) 2011, Charlie Robbins and the Contributors.
*

View file

@ -1,5 +1,5 @@
/*
* provider-argv.js: Test fixture for using optimist defaults with nconf.
* provider-argv.js: Test fixture for using yargs defaults with nconf.
*
* (C) 2011, Charlie Robbins and the Contributors.
*