Merge branch 'master' of https://github.com/indexzero/nconf into update-async

This commit is contained in:
Christian Murphy 2015-08-19 08:03:38 -07:00
commit be0ee00b2a
11 changed files with 117 additions and 102 deletions

View file

@ -1,4 +1,8 @@
# nconf [![Build Status](https://secure.travis-ci.org/flatiron/nconf.png)](http://travis-ci.org/flatiron/nconf) # nconf
[![Version npm](https://img.shields.io/npm/v/nconf.svg?style=flat-square)](https://www.npmjs.com/package/nconf)[![npm Downloads](https://img.shields.io/npm/dm/nconf.svg?style=flat-square)](https://www.npmjs.com/package/nconf)[![Build Status](https://img.shields.io/travis/indexzero/nconf/master.svg?style=flat-square)](https://travis-ci.org/indexzero/nconf)[![Dependencies](https://img.shields.io/david/indexzero/nconf.svg?style=flat-square)](https://david-dm.org/indexzero/nconf)
[![NPM](https://nodei.co/npm/nconf.png?downloads=true&downloadRank=true)](https://nodei.co/npm/nconf/)
Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging. Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.
@ -61,7 +65,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 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. 2. **nconf.env(options)** Loads `process.env` into the hierarchy.
3. **nconf.file(options)** Loads the configuration data at options.file 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. 4. **nconf.defaults(options)** Loads the data in options.store into the hierarchy.
@ -159,11 +163,11 @@ A simple in-memory storage engine that stores a nested JSON representation of th
``` ```
### Argv ### 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 ``` 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({ nconf.argv({
"x": { "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> <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> <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 by checking <code>yargs.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> 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> <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> <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="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="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="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="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="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> <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 () { Argv.prototype.loadArgv = function () {
var self = this, var self = this,
optimist, argv; yargs, argv;
optimist = typeof this.options === 'object' yargs = typeof this.options === 'object'
? require('optimist')(process.argv.slice(2)).options(this.options) ? require('yargs')(process.argv.slice(2)).options(this.options)
: require('optimist')(process.argv.slice(2)); : 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) { if (!argv) {
return; return;
@ -61,8 +61,8 @@ Argv.prototype.loadArgv = function () {
self.set(key, argv[key]); self.set(key, argv[key]);
}); });
this.showHelp = optimist.showHelp this.showHelp = yargs.showHelp
this.help = optimist.help this.help = yargs.help
this.readOnly = true; this.readOnly = true;
return this.store; return this.store;

View file

@ -24,7 +24,7 @@ var Env = exports.Env = function (options) {
this.whitelist = options.whitelist || []; this.whitelist = options.whitelist || [];
this.separator = options.separator || ''; this.separator = options.separator || '';
if (typeof options.match === 'function' if (({}).toString.call(options.match) === '[object RegExp]'
&& typeof options !== 'string') { && typeof options !== 'string') {
this.match = options.match; this.match = options.match;
} }

View file

@ -1,7 +1,7 @@
{ {
"name": "nconf", "name": "nconf",
"description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.", "description": "Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.",
"version": "0.7.1", "version": "0.7.2",
"author": "Charlie Robbins <charlie.robbins@gmail.com>", "author": "Charlie Robbins <charlie.robbins@gmail.com>",
"repository": { "repository": {
"type": "git", "type": "git",
@ -15,7 +15,7 @@
"dependencies": { "dependencies": {
"async": "^1.4.0", "async": "^1.4.0",
"ini": "^1.3.0", "ini": "^1.3.0",
"optimist": "~0.6.0" "yargs": "^3.19.0"
}, },
"devDependencies": { "devDependencies": {
"vows": "0.8.x" "vows": "0.8.x"

View file

@ -16,12 +16,23 @@ var fs = require('fs'),
var completeTest = helpers.fixture('complete-test.json'), var completeTest = helpers.fixture('complete-test.json'),
complete = helpers.fixture('complete.json'); complete = helpers.fixture('complete.json');
// prime the process.env
process.env['NCONF_foo'] = 'bar';
process.env.FOO = 'bar';
process.env.BAR = 'zalgo';
process.env.NODE_ENV = 'debug';
process.env.FOOBAR = 'should not load';
vows.describe('nconf/multiple-stores').addBatch({ vows.describe('nconf/multiple-stores').addBatch({
"When using the nconf with multiple providers": { "When using the nconf with multiple providers": {
topic: function () { topic: function () {
var that = this; var that = this;
helpers.cp(complete, completeTest, function () { helpers.cp(complete, completeTest, function () {
nconf.env(); nconf.env({
// separator: '__',
match: /^NCONF_/,
whitelist: ['NODE_ENV', 'FOO', 'BAR']
});
nconf.file({ file: completeTest }); nconf.file({ file: completeTest });
nconf.use('argv', { type: 'literal', store: data }); nconf.use('argv', { type: 'literal', store: data });
that.callback(); that.callback();
@ -34,7 +45,7 @@ vows.describe('nconf/multiple-stores').addBatch({
}, },
"env vars": { "env vars": {
"are present": function () { "are present": function () {
Object.keys(process.env).forEach(function (key) { ['NODE_ENV', 'FOO', 'BAR', 'NCONF_foo'].forEach(function (key) {
assert.equal(nconf.get(key), process.env[key]); assert.equal(nconf.get(key), process.env[key]);
}); });
} }

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. * (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, Charlie Robbins and the Contributors.
* (C) 2011, Sander Tolsma * (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. * (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. * (C) 2011, Charlie Robbins and the Contributors.
* *