Skip to content

Commit

Permalink
Merge pull request #526 from brittharr/fix-cli-passthrough
Browse files Browse the repository at this point in the history
Fix cli passthrough options
  • Loading branch information
mde committed Jun 17, 2020
2 parents ec66df2 + 0cf97ae commit 8831f6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ delete global.jake; // NO NOT WANT
program.setTaskNames = function (n) { this.taskNames = n; };

let ejs = require('../lib/ejs');
let { hyphenToCamel } = require('../lib/utils');
let fs = require('fs');
let args = process.argv.slice(2);
let usage = fs.readFileSync(`${__dirname}/../usage.txt`).toString();
Expand Down Expand Up @@ -126,7 +127,7 @@ function run() {
let pOpts = {};

for (let p in program.opts) {
let name = p.replace(/-[a-z]/g, (match) => { return match[1].toUpperCase(); });
let name = hyphenToCamel(p);
pOpts[name] = program.opts[p];
}

Expand All @@ -135,7 +136,7 @@ function run() {

// Same-named 'passthrough' opts
CLI_OPTS.forEach((opt) => {
let optName = opt.full;
let optName = hyphenToCamel(opt.full);
if (opt.passThrough && typeof pOpts[optName] != 'undefined') {
opts[optName] = pOpts[optName];
}
Expand Down
12 changes: 12 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,15 @@ exports.cache = {
this._data = {};
}
};

/**
* Transforms hyphen case variable into camel case.
*
* @param {String} string Hyphen case string
* @return {String} Camel case string
* @static
* @private
*/
exports.hyphenToCamel = function (str) {
return str.replace(/-[a-z]/g, (match) => { return match[1].toUpperCase(); });
}
6 changes: 6 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
let exec = require('child_process').execSync;
let fs = require('fs');
let assert = require('assert');

function run(cmd) {
Expand Down Expand Up @@ -31,6 +32,11 @@ suite('cli', function () {
assert.equal(o, '<h1>frang</h1>\n');
});

test('rendering, remove whitespace option (hyphen case)', function () {
let o = run('./bin/cli.js --rm-whitespace ./test/fixtures/rmWhitespace.ejs');
assert.equal(o, fs.readFileSync('test/fixtures/rmWhitespace.html', 'utf-8'));
});

});


0 comments on commit 8831f6c

Please sign in to comment.