Skip to content

Commit ab6e84c

Browse files
committed
Sort instances by tag value
1 parent 3f06772 commit ab6e84c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strconv"
1010
"strings"
1111
"sync"
12+
"sort"
1213
)
1314

1415
type Tag struct {
@@ -56,6 +57,11 @@ func getInstances(config Config) (clouds CloudInstances) {
5657
return
5758
}
5859

60+
type SortByTagValue []StrMap
61+
func (a SortByTagValue) Len() int { return len(a) }
62+
func (a SortByTagValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
63+
func (a SortByTagValue) Less(i, j int) bool { return a[i]["tag_value"] < a[j]["tag_value"]}
64+
5965
func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap) {
6066
// Fuzzy matching, like SublimeText
6167
filter = strings.Join(strings.Split(filter, ""), ".*?")
@@ -78,8 +84,10 @@ func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap
7884
}
7985
}
8086
}
87+
88+
sort.Sort(SortByTagValue(matched))
8189

82-
return
90+
return
8391
}
8492

8593
func formatMatchedInstance(inst StrMap) string {

0 commit comments

Comments
 (0)