/
teleportation_list.go
61 lines (50 loc) · 1019 Bytes
/
teleportation_list.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cmd
import (
"fmt"
"os"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
)
var (
teleportationListCmd = &cobra.Command{
Use: "list",
Short: "List teleportations",
Aliases: []string{"ls", "l"},
RunE: meepoTeleportationList,
}
)
func meepoTeleportationList(cmd *cobra.Command, args []string) error {
var err error
sdk, err := NewHTTPSDK(cmd)
if err != nil {
return err
}
tps, err := sdk.ListTeleportations()
if err != nil {
return err
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{
"Name",
"Transport",
"Portal",
"Source",
"Sink",
"Channels",
})
for _, tp := range tps {
table.Append([]string{
tp.Name,
tp.Transport.PeerID,
tp.Portal,
fmt.Sprintf("%s:%s", tp.Source.Network, tp.Source.Address),
fmt.Sprintf("%s:%s", tp.Sink.Network, tp.Sink.Address),
fmt.Sprintf("%d", len(tp.DataChannels)),
})
}
table.Render()
return nil
}
func init() {
teleportationCmd.AddCommand(teleportationListCmd)
}