Skip to content

Commit

Permalink
list: print output in order
Browse files Browse the repository at this point in the history
  • Loading branch information
ebarajas committed Dec 11, 2023
1 parent 648ce60 commit aed6b57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package cmd

import (
"cmp"
"fmt"
"os"
"slices"

"github.com/ebarped/kubeswap/pkg/kubeconfig"
"github.com/ebarped/kubeswap/pkg/kv"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -34,8 +37,6 @@ func listFunc(cmd *cobra.Command, args []string) {
}
defer db.Close()

var list []pterm.BulletListItem

items, err := db.GetAll()
if err != nil {
log.Error().Str("error", err.Error()).Msg("error listing items from database")
Expand All @@ -49,6 +50,11 @@ func listFunc(cmd *cobra.Command, args []string) {
return
}

slices.SortFunc(items, func(a, b kubeconfig.Kubeconfig) int {
return cmp.Compare(a.Name, b.Name)
})

list := make([]pterm.BulletListItem, 0, len(items))
for _, kc := range items {
list = append(list, pterm.BulletListItem{
Level: 0,
Expand Down

0 comments on commit aed6b57

Please sign in to comment.