Skip to content

Commit

Permalink
fix sort (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny0826 authored Jan 19, 2021
1 parent af19528 commit 183f3b8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/user"
"path/filepath"
"sort"
"strings"

"github.com/bndr/gotabulate"
Expand Down Expand Up @@ -86,23 +87,29 @@ func HashSufString(data string) string {
// PrintTable generate table
func PrintTable(config *clientcmdapi.Config) error {
var table [][]string
for key, obj := range config.Contexts {
sortedKeys := make([]string, 0)
for k := range config.Contexts {
sortedKeys = append(sortedKeys, k)
}
sort.Strings(sortedKeys)
ctx := config.Contexts
for _, k := range sortedKeys {
namespace := "default"
head := ""
if config.CurrentContext == key {
if config.CurrentContext == k {
head = "*"
}
if obj.Namespace != "" {
namespace = obj.Namespace
if ctx[k].Namespace != "" {
namespace = ctx[k].Namespace
}
if config.Clusters == nil {
continue
}
cluster, ok := config.Clusters[obj.Cluster]
cluster, ok := config.Clusters[ctx[k].Cluster]
if !ok {
continue
}
conTmp := []string{head, key, obj.Cluster, obj.AuthInfo, cluster.Server, namespace}
conTmp := []string{head, k, ctx[k].Cluster, ctx[k].AuthInfo, cluster.Server, namespace}
table = append(table, conTmp)
}

Expand Down

0 comments on commit 183f3b8

Please sign in to comment.