Skip to content

Commit

Permalink
Merge pull request #3 from ebarped/list/order-output
Browse files Browse the repository at this point in the history
list: print output in order
  • Loading branch information
ebarped authored Dec 11, 2023
2 parents 648ce60 + aed6b57 commit e177b06
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 e177b06

Please sign in to comment.