resolves #64 passing usage string to optimist
This commit is contained in:
parent
818526ca62
commit
4894c8fcf7
2 changed files with 19 additions and 10 deletions
|
@ -29,7 +29,11 @@ var Provider = exports.Provider = function (options) {
|
|||
// Define wrapper functions for using basic stores
|
||||
// in this instance
|
||||
//
|
||||
['argv', 'env'].forEach(function (type) {
|
||||
Provider.prototype['argv'] = function(options, usage) {
|
||||
return this.add('argv', options, usage);
|
||||
};
|
||||
|
||||
['env'].forEach(function (type) {
|
||||
Provider.prototype[type] = function (options) {
|
||||
return this.add(type, options);
|
||||
};
|
||||
|
@ -121,7 +125,7 @@ Provider.prototype.use = function (name, options) {
|
|||
// provider.add('memory');
|
||||
// provider.add('userconf', { type: 'file', filename: '/path/to/userconf' })
|
||||
//
|
||||
Provider.prototype.add = function (name, options) {
|
||||
Provider.prototype.add = function (name, options, usage) {
|
||||
options = options || {};
|
||||
var type = options.type || name;
|
||||
|
||||
|
@ -129,7 +133,7 @@ Provider.prototype.add = function (name, options) {
|
|||
throw new Error('Cannot add store with unknown type: ' + type);
|
||||
}
|
||||
|
||||
this.stores[name] = this.create(type, options);
|
||||
this.stores[name] = this.create(type, options, usage);
|
||||
|
||||
if (this.stores[name].loadSync) {
|
||||
this.stores[name].loadSync();
|
||||
|
@ -157,8 +161,8 @@ Provider.prototype.remove = function (name) {
|
|||
// Creates a store of the specified `type` using the
|
||||
// specified `options`.
|
||||
//
|
||||
Provider.prototype.create = function (type, options) {
|
||||
return new (require('../nconf')[common.capitalize(type.toLowerCase())])(options);
|
||||
Provider.prototype.create = function (type, options, usage) {
|
||||
return new (require('../nconf')[common.capitalize(type.toLowerCase())])(options, usage);
|
||||
};
|
||||
|
||||
//
|
||||
|
|
|
@ -14,12 +14,13 @@ var util = require('util'),
|
|||
// 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) {
|
||||
var Argv = exports.Argv = function (options, usage) {
|
||||
Memory.call(this, options);
|
||||
|
||||
this.type = 'argv';
|
||||
this.readOnly = true;
|
||||
this.options = options || false;
|
||||
this.usage = usage;
|
||||
};
|
||||
|
||||
// Inherit from the Memory store
|
||||
|
@ -41,11 +42,15 @@ Argv.prototype.loadSync = function () {
|
|||
//
|
||||
Argv.prototype.loadArgv = function () {
|
||||
var self = this,
|
||||
argv;
|
||||
optimist, argv;
|
||||
|
||||
argv = typeof this.options === 'object'
|
||||
? require('optimist')(process.argv.slice(2)).options(this.options).argv
|
||||
: require('optimist')(process.argv.slice(2)).argv;
|
||||
optimist = typeof this.options === 'object'
|
||||
? require('optimist')(process.argv.slice(2)).options(this.options)
|
||||
: require('optimist')(process.argv.slice(2));
|
||||
|
||||
if (typeof this.usage === 'string') { optimist.usage(this.usage) }
|
||||
|
||||
argv = optimist.argv
|
||||
|
||||
if (!argv) {
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue