From cb27c21252400a21b8d92654ebba7967cad44bf5 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Thu, 13 Apr 2023 17:03:24 +0900 Subject: [PATCH] feature. add long param to cluster-list --- internal/commands/cluster-list.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/commands/cluster-list.go b/internal/commands/cluster-list.go index 4de5bb3..af2937f 100644 --- a/internal/commands/cluster-list.go +++ b/internal/commands/cluster-list.go @@ -14,6 +14,7 @@ import ( func NewClusterListCommand(globalOpts *GlobalOptions) *cobra.Command { var ( organizationId string + long bool ) var command = &cobra.Command{ @@ -40,18 +41,19 @@ func NewClusterListCommand(globalOpts *GlobalOptions) *cobra.Command { var out domain.GetClustersResponse helper.Transcode(body, &out) - printClusters(out.Clusters) + printClusters(out.Clusters, long) return nil }, } command.Flags().StringVarP(&organizationId, "organization-id", "o", "", "the organizationId with clusters") + command.Flags().BoolVarP(&long, "long", "l", false, "enabled detail information") return command } -func printClusters(r []domain.ClusterResponse) { +func printClusters(r []domain.ClusterResponse, long bool) { if len(r) == 0 { fmt.Println("No cluster exists for specified organization!") return @@ -65,13 +67,27 @@ func printClusters(r []domain.ClusterResponse) { t.Style().Options.SeparateFooter = false t.Style().Options.SeparateHeader = false t.Style().Options.SeparateRows = false + t.AppendHeader(table.Row{"ORGANIZATION_ID", "NAME", "ID", "STATUS", "CREATED_AT", "UPDATED_AT"}) for _, s := range r { + fmt.Println(s.Status) + + if !long { + if s.Status == "DELETED" { + continue + } + } + tCreatedAt := helper.ParseTime(s.CreatedAt) tUpdatedAt := helper.ParseTime(s.UpdatedAt) t.AppendRow(table.Row{s.OrganizationId, s.Name, s.ID, s.Status, tCreatedAt, tUpdatedAt}) } - fmt.Println(t.Render()) + + if len(r) > 0 { + fmt.Println(t.Render()) + } else { + fmt.Println("No organization found.") + } } func ModelToJson(in any) string {