a strange bug
Last active
December 20, 2015 11:39
-
-
Save eins78/6125347 to your computer and use it in GitHub Desktop.
flatiron-nconf-wtf
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
/node_modules/ |
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
{ | |
"foo": "WTF" | |
} |
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
var flatiron = require('flatiron'), | |
path = require('path'), | |
app = flatiron.app; | |
app.config.argv(); | |
app.config.env(); | |
app.config.file({ file: 'config.json' }); | |
console.log('foo: ' + app.config.get('foo')); | |
app.init(); | |
console.log('foo: ' + app.config.get('foo')); |
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
var flatiron = require('flatiron'), | |
path = require('path'), | |
app = flatiron.app; | |
app.config.argv(); | |
app.config.env(); | |
app.config.file('file', { file: 'config.json' }); | |
app.use(flatiron.plugins.cli); | |
// we run this with `node file.js --foo=bar` | |
console.log('foo: ' + app.config.get('foo')); | |
// now, `foo` is equal to config from argv | |
// the `init` changes the `app.config` ??? | |
app.init(); | |
console.log('foo: ' + app.config.get('foo')); | |
// now, `foo` is equal to config from `file` :/ |
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
var fs = require('fs'), | |
nconf = require('nconf'); | |
// | |
// Setup nconf to use (in-order): | |
// 1. Command-line arguments | |
// 2. Environment variables | |
// 3. A file located at 'path/to/config.json' | |
// | |
nconf.argv() | |
.env() | |
.file({ file: 'config.json' }); | |
console.log('foo: ' + nconf.get('foo')); | |
console.log('foo: ' + nconf.get('foo')); |
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
{ | |
"name": "nconf-test", | |
"version": "0.0.0", | |
"description": "", | |
"main": "app.js", | |
"dependencies": { | |
"nconf": "~0.6.7", | |
"union": "0.3.5", | |
"flatiron": "0.3.8", | |
"vows": "~0.7.0" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "BSD" | |
} |
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
var vows = require('vows'), | |
assert = require('assert'), | |
exec = require('child_process').exec; | |
var expected = "foo: bar"; | |
function run (testfile, callback) { | |
var cmd = 'node ' + testfile + '.js --foo=bar'; | |
exec(cmd, function (err, stdout, stderr) { | |
callback(err || null, stdout); | |
}); | |
} | |
var suite = vows.describe('nconf + flatiron = WTF').export(module); | |
suite.addBatch({ | |
'Run just-nconf --foo=bar' : { | |
topic: function() { | |
run('just-nconf', this.callback); | |
}, | |
'foo=bar': function (topic) { | |
assert.equal(topic.split('\n')[0], expected); | |
} | |
}, | |
'Run flatiron-app --foo=bar' : { | |
topic: function() { | |
run('flatiron-app', this.callback); | |
}, | |
'foo=bar': function (topic) { | |
assert.equal(topic.split('\n')[0], expected); | |
}, | |
'foo=bar after init()': function (topic) { | |
assert.equal(topic.split('\n')[1], expected); | |
} | |
}, | |
'Run flatiron-cli --foo=bar' : { | |
topic: function() { | |
run('flatiron-cli', this.callback); | |
}, | |
'foo=bar': function (topic) { | |
assert.equal(topic.split('\n')[0], expected); | |
}, | |
'foo=bar after init()': function (topic) { | |
assert.equal(topic.split('\n')[1], expected); | |
} | |
} | |
}); | |
// suite.run(); | |
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
#!/bin/sh | |
echo "just-nconf" | |
node just-nconf.js --foo=bar | |
echo "flatiron-app" | |
node flatiron-app.js --foo=bar | |
echo "flatiron-cli.js" | |
node flatiron-cli.js --foo=bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment