Skip to content

Commit

Permalink
convert cli passthrough hyphen case options to camelcase before rende…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
brittharr committed Jun 15, 2020
1 parent 5c38c53 commit 0cf97ae
Show file tree
Hide file tree
Showing 2 changed files with 15 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(); });
}

0 comments on commit 0cf97ae

Please sign in to comment.