// @flow

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

module.exports = {
  command: 'netAddr',
  describe: `Print the local node's network addresses in multiaddr format.\n`,
  handler: subcommand((opts: {client: RestClient}) => {
    const {client} = opts

    return client.getNetAddresses()
      .then(
        addresses => {
          if (addresses.length < 1) {
            console.warn(
              'Local node does not have an address. Make sure status is set to "online" or "public"'
            )
          } else {
            addresses.forEach(addr => {
              console.log(addr)
            })
          }
        })
      .catch(
        err => { throw new Error(`Error retrieving addresses: ${err.message}`) }
      )
  })
}

@@ -135,16 +135,25 @@
 'netAddr
+ %5BpeerId%5D
 ',%0A  des
@@ -221,16 +221,120 @@
  format.
+ %60 +%0A    %60If 'peerId' is given, prints the locally known addresses for that peer (useful for debugging).
 %5Cn%60,%0A  h
@@ -378,16 +378,33 @@
 stClient
+, peerId?: string
 %7D) =%3E %7B%0A
@@ -420,16 +420,24 @@
  %7Bclient
+, peerId
 %7D = opts
@@ -472,16 +472,22 @@
 dresses(
+peerId
 )%0A      
@@ -570,22 +570,149 @@
     
-console.warn(%0A
+if (peerId != null) %7B%0A              console.warn(%60No known addresses for peer $%7BpeerId%7D%60)%0A            %7D else %7B%0A              console.warn(%0A  
     
@@ -820,17 +820,33 @@
         
-)
+  )%0A            %7D
 %0A       

add `peerId` arg to `mcclient netAddr`