const RestClient = require('../../api/RestClient');
const { subcommand, println } = require('../util');

module.exports = {
  command: 'ping <peerId>',
  describe: 'Ping a remote peer, identified by `peerId`. Deprecated in favor of `mcclient net ping`.' + 'Will attempt to lookup the peer with a configured directory server or DHT.\n',
  handler: subcommand(opts => {
    const { peerId, client } = opts;
    println('Pinging peer: ', peerId);

    return client.ping(peerId).then(success => println('Ping OK'), err => {
      throw new Error(`Error pinging: ${ err.message }`);
    });
  })
};