'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

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

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"); }); }; }

class SocketConfigSetCmd {
  constructor(context) {
    this.session = context.session;
    this.Socket = context.Socket;
  }

  run([socketName, optionName, optionValue, cmd]) {
    var _this = this;

    return _asyncToGenerator(function* () {
      _this.socket = yield _this.Socket.get(socketName);

      if (!_this.socket.existRemotely) {
        (0, _printTools.echo)();
        (0, _printTools.error)(4)('That socket was not synced!');
        (0, _printTools.echo)();
        process.exit(1);
      }

      if (!(_this.socket.spec.config && _this.socket.spec.config[optionName])) {
        (0, _printTools.warning)('No such config option!');
        process.exit();
      }

      const config = Object.assign({}, _this.socket.remote.config);

      config[optionName] = optionValue;
      return _this.socket.updateConfig(config).then(function (resp) {
        process.exit();
      }).catch(function (err) {
        (0, _printTools.error)(err.message);
      });
    })();
  }
}
exports.default = SocketConfigSetCmd;
module.exports = exports['default'];
//# sourceMappingURL=socket-config-set.js.map