'use strict';

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

module.exports = Command.extend({
  desc: 'Add a file to IPFS using the UnixFS data format',

  options: {
    recursive: {
      alias: 'r',
      type: 'boolean',
      default: false
    }
  },

  run: function run(recursive, path) {
    var node = new IPFS();
    path = process.cwd() + '/' + path;
    node.files.add(path, {
      recursive: recursive
    }, function (err, stats) {
      if (err) {
        return console.log(err);
      }
      console.log('added', bs58.encode(stats.Hash).toString(), stats.Name);
    });
  }
});