"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.runCommand = exports.getCommandAndArgvFromCli = exports.commandToFunction = exports.aliasToCommand = exports.isAlias = void 0;

var _commandLineCommands2 = _interopRequireDefault(require("command-line-commands"));

var _constants = require("./constants");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var isAlias = function isAlias(command) {
  return Object.keys(_constants.aliases).includes(command);
};

exports.isAlias = isAlias;

var aliasToCommand = function aliasToCommand(alias) {
  return _constants.aliases[alias];
};

exports.aliasToCommand = aliasToCommand;

var commandToFunction = function commandToFunction(command) {
  command = command || _constants.defaultCommand;

  if (isAlias(command)) {
    command = aliasToCommand(command);
  }

  return _constants.commandsMap[command];
};

exports.commandToFunction = commandToFunction;

var getCommandAndArgvFromCli = function getCommandAndArgvFromCli() {
  var _commandLineCommands = (0, _commandLineCommands2["default"])(_constants.availableCommandsList),
      command = _commandLineCommands.command,
      argv = _commandLineCommands.argv;

  return {
    command: command,
    argv: argv
  };
};

exports.getCommandAndArgvFromCli = getCommandAndArgvFromCli;

var runCommand = function runCommand(command, argv) {
  var commandFunction = commandToFunction(command);
  return commandFunction(argv);
};

exports.runCommand = runCommand;