"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.cliArgsToObject = cliArgsToObject;

/**
 * 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
 * 
 * retunr {"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 = option.slice(equIndex + 1);

      if (equIndex === -1) {
        key = option.slice(2);
        value = true;
      }

      key = key.replace(/-|:/g, '_');
      processEnv[key] = value;
    }
  });
  return processEnv;
}