-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] Refactor to make using nconf more fluent.
- Loading branch information
Showing
18 changed files
with
267 additions
and
293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* argv.js: Simple memory-based store for command-line arguments. | ||
* | ||
* (C) 2011, Charlie Robbins | ||
* | ||
*/ | ||
|
||
var util = require('util'), | ||
optimist = require('optimist'), | ||
Memory = require('./memory').Memory; | ||
|
||
// | ||
// ### function Argv (options) | ||
// #### @options {Object} Options for this instance. | ||
// Constructor function for the Argv nconf store, a simple abstraction | ||
// around the Memory store that can read command-line arguments. | ||
// | ||
var Argv = exports.Argv = function (options) { | ||
Memory.call(this, options); | ||
|
||
this.type = 'argv'; | ||
this.options = options || false; | ||
}; | ||
|
||
// Inherit from the Memory store | ||
util.inherits(Argv, Memory); | ||
|
||
// | ||
// ### function loadSync () | ||
// Loads the data passed in from `process.argv` into this instance. | ||
// | ||
Argv.prototype.loadSync = function () { | ||
this.loadArgv(); | ||
return this.store; | ||
}; | ||
|
||
// | ||
// ### function loadArgv () | ||
// Loads the data passed in from the command-line arguments | ||
// into this instance. | ||
// | ||
Argv.prototype.loadArgv = function () { | ||
var self = this, | ||
argv; | ||
|
||
argv = typeof this.options === 'object' | ||
? optimist(process.argv.slice(2)).options(this.options).argv | ||
: optimist(process.argv.slice(2)).argv; | ||
|
||
if (!argv) { | ||
return; | ||
} | ||
|
||
Object.keys(argv).forEach(function (key) { | ||
self.set(key, argv[key]); | ||
}); | ||
|
||
return this.store; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* env.js: Simple memory-based store for environment variables | ||
* | ||
* (C) 2011, Charlie Robbins | ||
* | ||
*/ | ||
|
||
var util = require('util'), | ||
Memory = require('./memory').Memory; | ||
|
||
// | ||
// ### function Env (options) | ||
// #### @options {Object} Options for this instance. | ||
// Constructor function for the Env nconf store, a simple abstraction | ||
// around the Memory store that can read process environment variables. | ||
// | ||
var Env = exports.Env = function (options) { | ||
Memory.call(this, options); | ||
|
||
this.type = 'env'; | ||
this.options = options || []; | ||
}; | ||
|
||
// Inherit from the Memory store | ||
util.inherits(Env, Memory); | ||
|
||
// | ||
// ### function loadSync () | ||
// Loads the data passed in from `process.env` into this instance. | ||
// | ||
Env.prototype.loadSync = function () { | ||
this.loadEnv(); | ||
return this.store; | ||
}; | ||
|
||
// | ||
// ### function loadEnv () | ||
// Loads the data passed in from `process.env` into this instance. | ||
// | ||
Env.prototype.loadEnv = function () { | ||
var self = this; | ||
|
||
Object.keys(process.env).filter(function (key) { | ||
return !self.options.length || self.options.indexOf(key) !== -1; | ||
}).forEach(function (key) { | ||
self.set(key, process.env[key]); | ||
}); | ||
|
||
return this.store; | ||
}; | ||
|
Oops, something went wrong.