diff --git a/cmd/cluster_list.go b/cmd/cluster_list.go index b211169..9696ba6 100644 --- a/cmd/cluster_list.go +++ b/cmd/cluster_list.go @@ -103,11 +103,11 @@ func printClusters(r *pb.GetClustersResponse, long bool) { t.Style().Options.SeparateHeader = false t.Style().Options.SeparateRows = false if long { - t.AppendHeader(table.Row{"Name", "ID", "Status", "CREATED_AT", "UPDATED_AT", "CSP_ID", "CONTRACT_ID"}) + t.AppendHeader(table.Row{"Name", "ID", "Status", "CREATED_AT", "UPDATED_AT", "CSP_ID", "CONTRACT_ID", "STATUS_DESC"}) for _, s := range r.Clusters { tCreatedAt := parseTime(s.CreatedAt) tUpdatedAt := parseTime(s.UpdatedAt) - t.AppendRow(table.Row{s.Name, s.Id, s.Status, tCreatedAt, tUpdatedAt, s.CspId, s.ContractId}) + t.AppendRow(table.Row{s.Name, s.Id, s.Status, tCreatedAt, tUpdatedAt, s.CspId, s.ContractId, s.StatusDesc}) } } else { t.AppendHeader(table.Row{"Name", "ID", "Status", "CREATED_AT", "UPDATED_AT"}) @@ -127,7 +127,7 @@ func parseTime(t *timestamppb.Timestamp) string { } func filterResponse(r *pb.GetClustersResponse) *pb.GetClustersResponse { - clusters := []*pb.Cluster {} + clusters := []*pb.Cluster{} for _, cluster := range r.Clusters { if cluster.GetStatus() != pb.ClusterStatus_DELETED { clusters = append(clusters, cluster) diff --git a/cmd/service_list.go b/cmd/service_list.go index 9c38688..c359389 100644 --- a/cmd/service_list.go +++ b/cmd/service_list.go @@ -38,7 +38,7 @@ var serviceListCmd = &cobra.Command{ Long: `Show list of service. Example: -tks service list `, +tks service list (--long)`, Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { fmt.Println("You must specify cluster ID.") @@ -80,7 +80,8 @@ tks service list `, if err != nil { fmt.Println(err) } else { - printAppGroups(r) + long, _ := cmd.Flags().GetBool("long") + printAppGroups(r, long) } }, } @@ -97,9 +98,10 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: // serviceListCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + serviceListCmd.Flags().BoolP("long", "l", false, "Print detail information") } -func printAppGroups(r *pb.GetAppGroupsResponse) { +func printAppGroups(r *pb.GetAppGroupsResponse, long bool) { t := table.NewWriter() tTemp := table.Table{} tTemp.Render() @@ -108,13 +110,25 @@ func printAppGroups(r *pb.GetAppGroupsResponse) { t.Style().Options.SeparateFooter = false t.Style().Options.SeparateHeader = false t.Style().Options.SeparateRows = false - t.AppendHeader(table.Row{"Type", "SERVICE_ID", "Status", "CREATED_AT", "UPDATED_AT"}) - for _, s := range r.AppGroups { - tCreatedAt := parseTime(s.CreatedAt) - tUpdatedAt := parseTime(s.UpdatedAt) - t.AppendRow(table.Row{s.Type, s.AppGroupId, s.Status, tCreatedAt, tUpdatedAt}) + if long { + t.AppendHeader(table.Row{"TYPE", "SERVICE_ID", "STATUS", "CREATED_AT", "UPDATED_AT", "UPDATE_DESC"}) + for _, s := range r.AppGroups { + tCreatedAt := parseTime(s.CreatedAt) + tUpdatedAt := parseTime(s.UpdatedAt) + + t.AppendRow(table.Row{s.Type, s.AppGroupId, s.Status, tCreatedAt, tUpdatedAt, s.StatusDesc}) + } + } else { + t.AppendHeader(table.Row{"TYPE", "SERVICE_ID", "STATUS", "CREATED_AT", "UPDATED_AT"}) + for _, s := range r.AppGroups { + tCreatedAt := parseTime(s.CreatedAt) + tUpdatedAt := parseTime(s.UpdatedAt) + + t.AppendRow(table.Row{s.Type, s.AppGroupId, s.Status, tCreatedAt, tUpdatedAt}) + } } + if len(r.AppGroups) > 0 { fmt.Println(t.Render()) } else { diff --git a/go.mod b/go.mod index 170e2ed..0cced44 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/jedib0t/go-pretty v4.3.0+incompatible github.com/matryer/is v1.4.0 github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc - github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49 + github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625 github.com/spf13/cobra v1.2.1 github.com/spf13/viper v1.9.0 golang.org/x/net v0.0.0-20211020060615-d418f374d309 // indirect diff --git a/go.sum b/go.sum index ba20764..eff27e8 100644 --- a/go.sum +++ b/go.sum @@ -440,6 +440,8 @@ github.com/openinfradev/tks-contract v0.1.1-0.20210928021110-fe2b666327cc/go.mod github.com/openinfradev/tks-proto v0.0.6-0.20210924020717-178698d59e9d/go.mod h1:WDzIQ7ayHVA7cA3Z+D2etK7gQuo4penewcC/cWcewlA= github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49 h1:XYNl9fXGUH02/Laqht+ba2FmgOXrl7sUDHcAZHsSaUE= github.com/openinfradev/tks-proto v0.0.6-0.20220324075944-e471af2c8c49/go.mod h1:3DrATRNCUJMW0oMLHT6D1teN4hX0vMGH4qOGnadakmo= +github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625 h1:kvcIa/cU+sjsK4VhQHjtquS3mGC3UAmbNHL9Qe03vYA= +github.com/openinfradev/tks-proto v0.0.6-0.20220406043255-9fffe49c4625/go.mod h1:3DrATRNCUJMW0oMLHT6D1teN4hX0vMGH4qOGnadakmo= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=