package cmd
import (
"context"
"io"
"github.com/spf13/cobra"
"github.com/gitpod-io/gitpod/common-go/log"
"github.com/gitpod-io/gitpod/ws-manager-bridge/api"
)
var clustersListCmd = &cobra.Command{
Use: "list",
Short: "Lists all clusters",
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conn, client, err := getClustersClient(ctx)
if err != nil {
log.WithError(err).Fatal("cannot connect")
}
defer conn.Close()
resp, err := client.List(ctx, &api.ListRequest{})
if err != nil && err != io.EOF {
log.Fatal(err)
}
tpl := `NAME URL STATIC STATE SCORE GOVERNED REGION ADMISSION CONSTRAINTS
{{- range .Status }}
{{ .Name }} {{ .Url }} {{ .Static }} {{ .State }} {{ .Score }} {{ .Governed }} {{ .Region }} {{ .AdmissionConstraint -}}
{{ end }}
`
err = getOutputFormat(tpl, "{..name}").Print(resp)
if err != nil {
log.Fatal(err)
}
},
}
func init() {
clustersCmd.AddCommand(clustersListCmd)
}