#!/usr/bin/env node
'use strict';

var _program = require('./program');

var _program2 = _interopRequireDefault(_program);

var _commands = require('./commands');

var _commands2 = _interopRequireDefault(_commands);

var _session = require('./utils/session');

var _session2 = _interopRequireDefault(_session);

var _context = require('./utils/context');

var _context2 = _interopRequireDefault(_context);

var _validateCommands = require('./utils/validate-commands');

var _validateCommands2 = _interopRequireDefault(_validateCommands);

var _printTools = require('./utils/print-tools');

var _analytics = require('./utils/analytics');

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

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

_context2.default.session.load().then(_asyncToGenerator(function* () {
  _program2.default.command('add <path>').group('Hosting').description('Create a new hosting').option('-c, --cname <cname>', 'CNAME'
  // .option('-s, --socket <name>', 'socket')
  ).action((() => {
    var _ref2 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      // await session.checkConnection();
      // if (options[1].socket) {
      //   session.hasSocket(options[1].socket);
      // }
      (0, _printTools.echo)();
      new _commands2.default.HostingAdd(_context2.default).run(options);
    });

    return function () {
      return _ref2.apply(this, arguments);
    };
  })());

  _program2.default.command('delete <name>').group('Hosting').description('Delete a hosting').option('-h, --help <topic>', 'Hosting name').action((() => {
    var _ref3 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      yield _session2.default.checkConnection();
      (0, _printTools.echo)();
      new _commands2.default.HostingDelete(_context2.default).run(options);
    });

    return function () {
      return _ref3.apply(this, arguments);
    };
  })());

  _program2.default.command('list').group('Hosting').description('List hostings'
  // .option('-s, --socket <name>', 'socket')
  ).action((() => {
    var _ref4 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      yield _session2.default.checkConnection();
      new _commands2.default.HostingList(_context2.default).run(options);
    });

    return function () {
      return _ref4.apply(this, arguments);
    };
  })());

  _program2.default.command('files <name>').group('Hosting').description('List hosting files'
  // .option('-s, --socket <name>', 'socket')
  ).action((() => {
    var _ref5 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      yield _session2.default.checkConnection();
      (0, _printTools.echo)();
      new _commands2.default.HostingFilesCmd(_context2.default).run(options);
    });

    return function () {
      return _ref5.apply(this, arguments);
    };
  })());

  _program2.default.command('sync <name>').group('Hosting').description('Publish your local hosting files').option('-s, --socket <name>', 'socket').action((() => {
    var _ref6 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      yield _session2.default.checkConnection();
      (0, _printTools.echo)();
      new _commands2.default.HostingSync(_context2.default).run(options);
    });

    return function () {
      return _ref6.apply(this, arguments);
    };
  })());

  _program2.default.command('config').group('Hosting').description('Configure hosting parameters').option('-c, --cname <domain_name>', 'domain name').action((() => {
    var _ref7 = _asyncToGenerator(function* (...options) {
      (0, _analytics.trackCommand)(options);
      _session2.default.isAuthenticated();
      _session2.default.hasProject();
      yield _session2.default.checkConnection();
      (0, _printTools.echo)();
      new _commands2.default.HostingConfig(_context2.default).run(options);
    });

    return function () {
      return _ref7.apply(this, arguments);
    };
  })());

  _program2.default.on('*', function (commandsArr) {
    return (0, _validateCommands2.default)(commandsArr);
  });

  if (!process.argv.slice(2).length) {
    _program2.default.outputHelp();
  }

  _program2.default.parse(process.argv);
}));
//# sourceMappingURL=cli-hosting.js.map