forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnet_find.go
More file actions
42 lines (34 loc) · 846 Bytes
/
net_find.go
File metadata and controls
42 lines (34 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package cmd
import (
"context"
"encoding/json"
"errors"
"github.com/caarlos0/spin"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/spf13/cobra"
)
func init() {
netCmd.AddCommand(netFindCmd)
}
var netFindCmd = &cobra.Command{
Use: "find [peerID]",
Short: "Find a peer by peer id",
Long: `Find a peer by peer id`,
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), cmdTimeout)
defer cancel()
if len(args) != 1 {
Fatal(errors.New("you must provide a peer id argument"))
}
s := spin.New("%s Finding peer...")
s.Start()
peerID, err := peer.Decode(args[0])
checkErr(err)
peerInfo, err := fcClient.Net.FindPeer(ctx, peerID)
s.Stop()
checkErr(err)
bytes, err := json.MarshalIndent(peerInfo, "", " ")
checkErr(err)
Success(string(bytes))
},
}