add stateMap for consistent state sorting

This commit is contained in:
Bradley Cicenas 2017-03-01 11:03:57 +11:00
parent 2c198ae2a0
commit 423ad8e753

18
sort.go
View File

@ -9,6 +9,13 @@ import (
type sortMethod func(c1, c2 *Container) bool
var stateMap = map[string]int{
"running": 3,
"paused": 2,
"exited": 1,
"created": 0,
}
var idSorter = func(c1, c2 *Container) bool { return c1.id < c2.id }
var nameSorter = func(c1, c2 *Container) bool { return c1.name < c2.name }
@ -50,16 +57,7 @@ var Sorters = map[string]sortMethod{
if c1.state == c2.state {
return nameSorter(c1, c2)
}
if c1.state == "running" {
return true
}
if c2.state == "running" {
return false
}
if c2.state == "paused" {
return false
}
return true
return stateMap[c1.state] > stateMap[c2.state]
},
}