@zohodesk/client_build_tool
Version:
A CLI tool to build web applications and client libraries
39 lines (33 loc) • 1.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.cliArgsToObject = cliArgsToObject;
var _giveDefaultValue = require("./giveDefaultValue");
/**
* experimental argument parsing logic
* @param {Array} cliArgs is when we use cli the options or args
*
* cliArgs:-
* `cbt start --port=2332 --mode=prod` in this command
* ['--port=2332', '--mode=prod'] these are cliArgs
*
* return {"port": 2332, "mode":"prod"}
*/
function cliArgsToObject(cliArgs) {
const processEnv = {};
cliArgs.forEach(option => {
if (/^--./.test(option)) {
const equIndex = option.indexOf('='); // equIndex = equIndex === -1 ? option.length : equIndex;
let key = option.slice(2, equIndex);
let value = (0, _giveDefaultValue.giveDefaultValue)(option.slice(equIndex + 1));
if (equIndex === -1) {
key = option.slice(2);
value = true;
}
key = key.replace(/-|:/g, '_');
processEnv[key] = value;
}
});
return processEnv;
}