pkg/utils: Add function to sort sets of containers or images in JSON
https://github.com/containers/toolbox/pull/318
This commit is contained in:
parent
928bf53943
commit
74c2d7f02b
1 changed files with 12 additions and 0 deletions
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"syscall"
|
||||
|
||||
"github.com/containers/toolbox/pkg/shell"
|
||||
|
@ -208,3 +209,14 @@ func ShowManual(manual string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SortJSON(json []map[string]interface{}, key string, hasInterface bool) []map[string]interface{} {
|
||||
sort.Slice(json, func(i, j int) bool {
|
||||
if hasInterface {
|
||||
return json[i][key].([]interface{})[0].(string) < json[j][key].([]interface{})[0].(string)
|
||||
}
|
||||
return json[i][key].(string) < json[j][key].(string)
|
||||
})
|
||||
|
||||
return json
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue