const getopts = require('getopts');

const alias = require('../alias');

/**
 * @returns {[string, {}, string[]]}
 */
function extractCommand() {
  const { _, ...options } = getopts(process.argv.slice(2), {
    alias,
  });
  const [firstCommand, ...restOfCommands] = _;

  return [firstCommand || 'default', options, restOfCommands || []];
}

module.exports = extractCommand;
