Merge PR #6 from 'pinheadmz/filter-options'

This commit is contained in:
Matthew Zipkin 2021-10-06 10:18:16 -04:00
commit 2e88341820
No known key found for this signature in database
GPG Key ID: E7E2984B6289C93A
2 changed files with 42 additions and 0 deletions

View File

@ -166,6 +166,7 @@ class Config {
_filter(name, this.args, child.args); _filter(name, this.args, child.args);
_filter(name, this.query, child.query); _filter(name, this.query, child.query);
_filter(name, this.hash, child.hash); _filter(name, this.hash, child.hash);
_filter(name, this.options, child.options);
return child; return child;
} }

41
test/bcfg-test.js Normal file
View File

@ -0,0 +1,41 @@
'use strict';
const assert = require('bsert');
const Config = require('../lib/config');
describe('bcfg', function() {
it('should filter options', () => {
const options = {
testString: 'hello',
childTestString: 'goodbye'
};
const parent = new Config('bcfg');
parent.inject(options);
parent.load(options);
assert.strictEqual(parent.str('test-string'), 'hello');
const child = parent.filter('child');
assert.strictEqual(child.str('test-string'), 'goodbye');
});
it('should filter argv', () => {
const parent = new Config('bcfg');
// process.argv
parent.parseArg([
'node',
'bcfg',
'--test-string=hello',
'--child-test-string=goodbye'
]);
assert.strictEqual(parent.str('test-string'), 'hello');
const child = parent.filter('child');
assert.strictEqual(child.str('test-string'), 'goodbye');
});
});