Skip to content

Commit

Permalink
feature. add cluster status description
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Apr 25, 2022
1 parent 7ca9de8 commit 41c17ea
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
6 changes: 3 additions & 3 deletions cmd/cluster_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand All @@ -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)
Expand Down
30 changes: 22 additions & 8 deletions cmd/service_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var serviceListCmd = &cobra.Command{
Long: `Show list of service.
Example:
tks service list <CLUSTER ID>`,
tks service list <CLUSTER ID> (--long)`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("You must specify cluster ID.")
Expand Down Expand Up @@ -80,7 +80,8 @@ tks service list <CLUSTER ID>`,
if err != nil {
fmt.Println(err)
} else {
printAppGroups(r)
long, _ := cmd.Flags().GetBool("long")
printAppGroups(r, long)
}
},
}
Expand All @@ -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()
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 41c17ea

Please sign in to comment.