-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.go
50 lines (42 loc) · 1.07 KB
/
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
package paratime
import (
"sort"
"github.com/spf13/cobra"
"github.com/oasisprotocol/cli/cmd/common"
cliConfig "github.com/oasisprotocol/cli/config"
"github.com/oasisprotocol/cli/table"
)
var listCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List configured ParaTimes",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
cfg := cliConfig.Global()
table := table.New()
table.SetHeader([]string{"Network", "Paratime", "ID"})
var output [][]string
for netName, net := range cfg.Networks.All {
for ptName, pt := range net.ParaTimes.All {
displayPtName := ptName
if net.ParaTimes.Default == ptName {
displayPtName += common.DefaultMarker
}
output = append(output, []string{
netName,
displayPtName,
pt.ID,
})
}
}
// Sort output by network name and paratime name.
sort.Slice(output, func(i, j int) bool {
if output[i][0] != output[j][0] {
return output[i][0] < output[j][0]
}
return output[i][1] < output[j][1]
})
table.AppendBulk(output)
table.Render()
},
}