'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };

var Command = require('ronin').Command;
var utils = require('../utils');
var debug = require('debug');
var log = debug('cli:version');
log.error = debug('cli:version:error');

module.exports = Command.extend({
  desc: 'Shows IPFS version information',

  options: {
    number: {
      alias: 'n',
      type: 'boolean',
      default: false
    },
    commit: {
      type: 'boolean',
      default: false
    },
    repo: {
      type: 'boolean',
      default: false
    }
  },

  run: function run() {
    utils.getIPFS(function (err, ipfs) {
      if (err) {
        throw err;
      }
      ipfs.version(function (err, version) {
        if (err) {
          return log.error(err);
        }

        if ((typeof version === 'undefined' ? 'undefined' : _typeof(version)) === 'object') {
          // js-ipfs-api output
          console.log('ipfs version', version.Version);
          return;
        }

        console.log('ipfs version', version);
      });
    });
  }
});