Skip to content

Commit

Permalink
Sort output for instance and diskimage (#494)
Browse files Browse the repository at this point in the history
* sort diskimage

* sort instance_list.go
  • Loading branch information
uzaxirr authored Jan 20, 2025
1 parent 55b7621 commit 6ed3764
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/diskimage/disk_image_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package diskimage

import (
"os"
"sort"

"github.com/civo/cli/common"
"github.com/civo/cli/config"
Expand Down Expand Up @@ -61,6 +62,11 @@ Example: civo diskimage ls -o=custom -f=id,name`,
})
}

// Sort the diskImageList by Name
sort.Slice(diskImageList, func(i, j int) bool {
return diskImageList[i].Name < diskImageList[j].Name
})

ow := utility.NewOutputWriter()

for _, diskImage := range diskImageList {
Expand Down
6 changes: 6 additions & 0 deletions cmd/instance/instance_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instance

import (
"os"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -58,6 +59,11 @@ If you wish to use a custom format, the available fields are:
os.Exit(1)
}

// Sort instances by hostname
sort.Slice(instances, func(i, j int) bool {
return instances[i].Hostname < instances[j].Hostname
})

ow := utility.NewOutputWriter()
for _, instance := range instances {
ow.StartLine()
Expand Down

0 comments on commit 6ed3764

Please sign in to comment.