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

module.exports = {
  command: 'id [peerId]',
  description: 'Request the peer id, publisher id, and info string of the local node, ' + 'or a remote peer if `peerId` is given and a directory server is connected.\n',
  handler: subcommand(opts => {
    const { client, peerId } = opts;
    return client.id(peerId).then(printIds);
  })
};

function printIds(opts) {
  const { peer, publisher, info } = opts;
  println(`Peer ID: ${ peer }`);
  println(`Publisher ID: ${ publisher }`);
  println(`Info: ${ info }`);
}