Skip to content

Commit

Permalink
Add Active column to tsh clusters output
Browse files Browse the repository at this point in the history
Its purpose is to indicate the user's selected cluster.
  • Loading branch information
andrejtokarcik committed Dec 4, 2020
1 parent f7520fc commit 5d6fb36
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tool/tsh/tsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -1052,16 +1052,27 @@ func onListClusters(cf *CLIConf) {
utils.FatalError(err)
}

profile, _, err := client.Status("", cf.Proxy)
if err != nil {
utils.FatalError(err)
}
showActive := func(cluster services.RemoteCluster) string {
if profile.Cluster == cluster.GetName() {
return "*"
}
return ""
}

var t asciitable.Table
if cf.Quiet {
t = asciitable.MakeHeadlessTable(3)
t = asciitable.MakeHeadlessTable(4)
} else {
t = asciitable.MakeTable([]string{"Cluster Name", "Status", "Cluster Type"})
t = asciitable.MakeTable([]string{"Cluster Name", "Status", "Cluster Type", "Active"})
}

t.AddRow([]string{rootCluster.GetName(), rootCluster.GetConnectionStatus(), "root"})
t.AddRow([]string{rootCluster.GetName(), rootCluster.GetConnectionStatus(), "root", showActive(rootCluster)})
for _, cluster := range leafClusters {
t.AddRow([]string{cluster.GetName(), cluster.GetConnectionStatus(), "leaf"})
t.AddRow([]string{cluster.GetName(), cluster.GetConnectionStatus(), "leaf", showActive(cluster)})
}
fmt.Println(t.AsBuffer().String())
}
Expand Down

0 comments on commit 5d6fb36

Please sign in to comment.