Skip to content

Commit

Permalink
Sort instances by tag value
Browse files Browse the repository at this point in the history
  • Loading branch information
buger committed Jun 26, 2014
1 parent 3f06772 commit ab6e84c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"sync"
"sort"
)

type Tag struct {
Expand Down Expand Up @@ -56,6 +57,11 @@ func getInstances(config Config) (clouds CloudInstances) {
return
}

type SortByTagValue []StrMap
func (a SortByTagValue) Len() int { return len(a) }
func (a SortByTagValue) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByTagValue) Less(i, j int) bool { return a[i]["tag_value"] < a[j]["tag_value"]}

func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap) {
// Fuzzy matching, like SublimeText
filter = strings.Join(strings.Split(filter, ""), ".*?")
Expand All @@ -78,8 +84,10 @@ func getMatchedInstances(clouds CloudInstances, filter string) (matched []StrMap
}
}
}

sort.Sort(SortByTagValue(matched))

return
return
}

func formatMatchedInstance(inst StrMap) string {
Expand Down

0 comments on commit ab6e84c

Please sign in to comment.