/
list.go
48 lines (39 loc) · 984 Bytes
/
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
package cmd
import (
"fmt"
"os"
pkgcmd "github.com/rancherlabs/corral/pkg/cmd"
"github.com/rancherlabs/corral/pkg/config"
"github.com/rancherlabs/corral/pkg/corral"
"github.com/spf13/cobra"
)
func NewCommandList() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all corrals on this system.",
Long: "List all corrals on this system.",
RunE: list,
}
cmd.Flags().VarP(&output, "output", "o", "Output format. One of: table|json|yaml")
return cmd
}
func list(_ *cobra.Command, _ []string) error {
corralNames, _ := os.ReadDir(config.CorralRoot("corrals"))
corrals := map[string]string{}
for _, entry := range corralNames {
c, err := corral.Load(config.CorralRoot("corrals", entry.Name()))
if err != nil {
continue
}
corrals[c.Name] = c.Status.String()
}
out, err := pkgcmd.Output(corrals, output, pkgcmd.OutputOptions{
Key: "NAME",
Value: "STATUS",
})
if err != nil {
return err
}
fmt.Println(out)
return nil
}