From de951cb771e7352f99f881601b7ef65cca1031da Mon Sep 17 00:00:00 2001 From: Matt Simerson Date: Thu, 20 Oct 2016 12:13:48 -0700 Subject: [PATCH] add wildcard boolean support (#3) with *.bool_option syntax --- .travis.yml | 16 ++++++++-------- package.json | 10 ++++++---- readers/ini.js | 7 +++++-- test/config.js | 4 +++- test/config/test.ini | 6 ++++++ test/readers/ini.js | 13 ++++++++++++- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c30f74..ee93330 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,18 @@ language: node_js node_js: - - "4.3" - - "5.6" + - "4" + - "6" before_script: - - npm install -g grunt-cli +# - npm install -g grunt-cli script: - - grunt lint - - node run_tests + - npm run lint + - npm test after_success: - - npm install istanbul codecov.io - - ./node_modules/istanbul/lib/cli.js cov run_tests - - cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js + - npm install istanbul codecov + - npm run coverage + - ./node_modules/.bin/codecov sudo: false diff --git a/package.json b/package.json index 3207dee..fd8ac75 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "haraka-config", "license": "MIT", "description": "Haraka's config file loader", - "version": "1.0.3", + "version": "1.0.4", "homepage": "http://haraka.github.io", "repository": { "type": "git", @@ -11,7 +11,7 @@ }, "main": "config.js", "engines": { - "node": ">= 0.10.43" + "node": ">= 0.12.16" }, "dependencies": { "js-yaml": "^3.5.3" @@ -55,7 +55,7 @@ }, "optionalDependencies": {}, "devDependencies": { - "eslint": ">=2.0.0", + "eslint": ">=2", "grunt": "*", "grunt-eslint": "*", "nodeunit": "^0.9.1" @@ -65,6 +65,8 @@ "url": "https://github.com/haraka/haraka-config/issues" }, "scripts": { - "test": "./run_tests" + "test": "./run_tests", + "lint": "./node_modules/.bin/grunt lint", + "coverage": "./node_modules/.bin/istanbul cov run_tests" } } diff --git a/readers/ini.js b/readers/ini.js index e79d189..f1ce165 100644 --- a/readers/ini.js +++ b/readers/ini.js @@ -60,8 +60,11 @@ exports.load = function (name, options, regex) { } if (options && Array.isArray(options.booleans) && - exports.bool_matches.indexOf( - current_sect_name + '.' + match[1]) !== -1) { + ( + exports.bool_matches.indexOf(current_sect_name + '.' + match[1]) !== -1 + || + exports.bool_matches.indexOf('*.' + match[1]) !== -1 + )) { current_sect[match[1]] = regex.is_truth.test(match[2]); // var msg = 'Using boolean ' + current_sect[match[1]] + // ' for ' + current_sect_name + '.' + match[1] + '=' + match[2]; diff --git a/test/config.js b/test/config.js index 10d68be..0e64964 100644 --- a/test/config.js +++ b/test/config.js @@ -236,7 +236,9 @@ exports.get = { array_test: { hostlist: [ 'first_host', 'second_host', 'third_host' ], intlist: [ '123', '456', '789' ], - } + }, + 'foo.com': { is_bool: 'true' }, + 'bar.com': { is_bool: 'false' } }); }, diff --git a/test/config/test.ini b/test/config/test.ini index a87e109..f08d1b6 100644 --- a/test/config/test.ini +++ b/test/config/test.ini @@ -35,3 +35,9 @@ hostlist[] = third_host intlist[] = 123 intlist[] = 456 intlist[] = 789 + +[foo.com] +is_bool=true + +[bar.com] +is_bool=false diff --git a/test/readers/ini.js b/test/readers/ini.js index e1f3043..4859566 100644 --- a/test/readers/ini.js +++ b/test/readers/ini.js @@ -4,7 +4,9 @@ var regex = require('../../configfile').regex; var _set_up = function (done) { this.ini = require('../../readers/ini'); - this.opts = { booleans: ['main.bool_true','main.bool_false'] }; + this.opts = { + booleans: [ 'main.bool_true', 'main.bool_false' ] + }; done(); }; @@ -74,6 +76,15 @@ exports.load = { test.strictEqual(r.sect1.bool_false_default, false); test.done(); }, + 'test.ini, wildcard boolean' : function (test) { + test.expect(2); + var r = this.ini.load('test/config/test.ini', { + booleans: [ '*.is_bool' ] + }, regex); + test.strictEqual(r['foo.com'].is_bool, true); + test.strictEqual(r['bar.com'].is_bool, false); + test.done(); + }, }; exports.empty = {