"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.validateOptions = exports.getOptions = void 0;

var _commandLineArgs2 = _interopRequireDefault(require("command-line-args"));

var _chalk = _interopRequireDefault(require("chalk"));

var _lodash = require("lodash");

var _help = _interopRequireDefault(require("./help"));

var _optionDefinitions = _interopRequireDefault(require("./option-definitions"));

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

var getOptions = function getOptions(argv) {
  var _commandLineArgs = (0, _commandLineArgs2["default"])(_optionDefinitions["default"], {
    argv: argv
  }),
      seederName = _commandLineArgs.name,
      helpWanted = _commandLineArgs.help;

  var options = {
    seederName: seederName,
    helpWanted: helpWanted
  };
  validateOptions(options);
  return options;
};

exports.getOptions = getOptions;

var validateOptions = function validateOptions() {
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
      seederName = _ref.seederName,
      helpWanted = _ref.helpWanted;

  if (!helpWanted && (typeof seederName !== 'string' || (0, _lodash.trim)(seederName).length < 3)) {
    console.log("".concat(_chalk["default"].red('ERROR'), " Please choose a seeder name"));
    console.log();
    (0, _help["default"])();
    throw new Error('exit');
  }
};

exports.validateOptions = validateOptions;