{"size": 1239, "ext": "js", "max_stars_repo_path": "modules/cmdLine/index.js", "max_stars_repo_name": "evanmags/snippets", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "modules/cmdLine/index.js", "max_issues_repo_name": "evanmags/snippets", "max_issues_repo_issues_event_min_datetime": "2020-09-04T21:02:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T04:48:18.000Z", "max_forks_repo_path": "modules/cmdLine/index.js", "max_forks_repo_name": "evanmags/snippets", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 30.975, "max_line_length": 91, "alphanum_fraction": 0.6351896691}
const inquire = require('inquirer');
const cmdDelete = require('./cmdDelete');
const cmdUpdate = require('./cmdUpdate');
const cmdSave = require('./cmdSave');
const cmdGet = require('./cmdGet');

/**
 * switch controller for the CLI when not run by passing arguments.
 * @param {*} user
 * @returns {null} function call or runs itself recurrsively
 */

async function CLIcontroller(user) {
  const mode = await inquire.prompt([
    {
      type: 'checkbox',
      name: 'mode',
      message: 'What would you like to do?',
      choices: [
        { name: 'Save a snippet', value: 'save' },
        { name: 'Get a snippet', value: 'get' },
        { name: 'Update a snippet', value: 'update' },
        { name: 'Delete a snippet', value: 'delete' },
      ],
    },
  ]).then((data) => { return data.mode[0]; });

  // need to pass user to all other functions to avoid making more requests than necessary.
  // will require restructuring all requests and command line functions.
  switch (mode) {
    case 'save': return cmdSave(user);
    case 'get': return cmdGet(user);
    case 'update': return cmdUpdate(user);
    case 'delete': return cmdDelete(user);
    default: return CLIcontroller(user);
  }
}

module.exports = CLIcontroller;
