'use strict';

var _typeof2 = require('babel-runtime/helpers/typeof');

var _typeof3 = _interopRequireDefault(_typeof2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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' : (0, _typeof3.default)(version)) === 'object') {
          // js-ipfs-api output
          console.log('ipfs version', version.Version);
          return;
        }

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