-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
list.go
58 lines (51 loc) · 1.53 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
51
52
53
54
55
56
57
58
package clustertemplate
import (
"fmt"
"log"
"os"
"text/tabwriter"
"github.com/spf13/cobra"
"github.com/argoproj/argo-workflows/v3/cmd/argo/commands/client"
"github.com/argoproj/argo-workflows/v3/pkg/apiclient/clusterworkflowtemplate"
wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
)
type listFlags struct {
output string // --output
}
func NewListCommand() *cobra.Command {
var listArgs listFlags
command := &cobra.Command{
Use: "list",
Short: "list cluster workflow templates",
Run: func(cmd *cobra.Command, args []string) {
ctx, apiClient := client.NewAPIClient()
serviceClient := apiClient.NewClusterWorkflowTemplateServiceClient()
cwftmplList, err := serviceClient.ListClusterWorkflowTemplates(ctx, &clusterworkflowtemplate.ClusterWorkflowTemplateListRequest{})
if err != nil {
log.Fatal(err)
}
switch listArgs.output {
case "", "wide":
printTable(cwftmplList.Items)
case "name":
for _, cwftmp := range cwftmplList.Items {
fmt.Println(cwftmp.ObjectMeta.Name)
}
default:
log.Fatalf("Unknown output mode: %s", listArgs.output)
}
},
}
command.Flags().StringVarP(&listArgs.output, "output", "o", "", "Output format. One of: wide|name")
return command
}
func printTable(wfList []wfv1.ClusterWorkflowTemplate) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
_, _ = fmt.Fprint(w, "NAME")
_, _ = fmt.Fprint(w, "\n")
for _, wf := range wfList {
_, _ = fmt.Fprintf(w, "%s\t", wf.ObjectMeta.Name)
_, _ = fmt.Fprintf(w, "\n")
}
_ = w.Flush()
}