Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reparse argv #17

Merged
merged 2 commits into from
Nov 20, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/nconf/stores/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

var util = require('util'),
optimist = require('optimist'),
Memory = require('./memory').Memory;

//
Expand Down Expand Up @@ -79,10 +80,10 @@ System.prototype.loadArgv = function () {
argv;

if (typeof this.argv === 'object') {
argv = require('optimist').options(this.argv).argv;
argv = optimist(process.argv.slice(2)).options(this.argv).argv;
}
else if (this.argv) {
argv = require('optimist').argv;
argv = optimist(process.argv.slice(2)).argv;
}

if (!argv) {
Expand Down Expand Up @@ -114,4 +115,5 @@ System.prototype.loadEnv = function () {
});

return this.store;
};
};

18 changes: 18 additions & 0 deletions test/fixtures/scripts/nconf-change-argv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* nconf-change-argv.js: Test fixture for changing argv on the fly
*
* (C) 2011, Charlie Robbins
*
*/

var nconf = require('../../../lib/nconf');

nconf.argv = true;

//
// Remove 'badValue', 'evenWorse' and 'OHNOEZ'
//
process.argv.splice(3, 3);
nconf.system.loadArgv();
process.stdout.write(nconf.get('something'));

7 changes: 6 additions & 1 deletion test/provider-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ vows.describe('nconf/provider').addBatch({
"when 'env' is set to true": helpers.assertSystemConf({
script: path.join(fixturesDir, 'scripts', 'nconf-env.js'),
env: { SOMETHING: 'foobar' }
}),
"when 'argv' is set to true and process.argv is modified": helpers.assertSystemConf({
script: path.join(fixturesDir, 'scripts', 'nconf-change-argv.js'),
argv: ['--something', 'badValue', 'evenWorse', 'OHNOEZ', 'foobar']
})
}
}
Expand Down Expand Up @@ -84,4 +88,5 @@ vows.describe('nconf/provider').addBatch({
}
}
}
}).export(module);
}).export(module);