From 0cf97ae9b42715e132411d1ac0468ed0272a6037 Mon Sep 17 00:00:00 2001 From: Brittany Harris Date: Mon, 15 Jun 2020 13:39:10 +0100 Subject: [PATCH] convert cli passthrough hyphen case options to camelcase before rendering --- bin/cli.js | 5 +++-- lib/utils.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 25c00810..0feab0b4 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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(); @@ -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]; } @@ -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]; } diff --git a/lib/utils.js b/lib/utils.js index 5715c177..a4c919f0 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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(); }); +} \ No newline at end of file