{"size": 1872, "ext": "js", "max_stars_repo_path": "src/setOptions.js", "max_stars_repo_name": "OzoneTank/templafy", "max_stars_repo_stars_event_min_datetime": "2018-02-22T14:11:54.000Z", "max_stars_repo_stars_event_max_datetime": "2018-02-22T14:11:54.000Z", "max_issues_repo_path": "src/setOptions.js", "max_issues_repo_name": "OzoneTank/simple-template-tool", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/setOptions.js", "max_forks_repo_name": "OzoneTank/simple-template-tool", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.7674418605, "max_line_length": 55, "alphanum_fraction": 0.5133547009}
const startAtIndex = 2; // will be 1 eventually I think

const setOptions = (args) => {
  const options = {
    args: [],
    badOptions: [],
    forceTemplate: false,
    help: false,
    interactive: undefined,
    mode: undefined,
    listTemplates: false,
    listStructures: false,
    templateInfo: {},
    leftVar: '/*{',
    rightVar: '}*/',
    verbose: false,
  };

  if (args.length <= startAtIndex) {
    options.help = true;
  }

  args.forEach(function (arg, i) {
    if (i < startAtIndex) {
      return;
    }
    const split = arg.split('=');
    let option = split[0];
    const value = split.slice(1).join('=');

    switch (option) {
      case '-h':
      case '--help':
        options.help = true;
        return;
      case '-m':
      case '--mode':
        options.mode = value;
        return;
      case '-l':
      case '--list':
      case '--list-templates':
        options.listTemplates = true;
        return;
      case '--list-structures':
        options.listStructures = true;
        return;
      case '--leftVar':
        options.leftVar = value;
        return;
      case '-p':
      case '-print':
        options.verbose = true;
        return;
      case '--rightVar':
        options.rightVar = value;
        return;
      case '-t':
      case '-template':
        options.forceTemplate = true;
        return;
      case '-i':
      case '--interactive':
        options.interactive = true;
        return;
      case '--vars':
        options.templateInfo = JSON.parse(value);
        return;
      default:
        if (option.indexOf('-') === 0) {
          options.badOptions.push(option);
          return;
        }
        if (option.endsWith('/')) {
          option = option.slice(0, -1);
        }
        options.args.push(option);
        return;
    }
  });

  return options;
};

module.exports = setOptions;
