pkg/utils: Add function to join sets of containers or images in JSON

https://github.com/containers/toolbox/pull/318
This commit is contained in:
Harry Míchal 2020-05-06 14:22:23 +02:00 committed by Debarshi Ray
parent 6170f494aa
commit 928bf53943
1 changed files with 22 additions and 0 deletions

View File

@ -159,6 +159,28 @@ func IsInsideToolboxContainer() bool {
return false
}
func JoinJSON(joinkey string, maps ...[]map[string]interface{}) []map[string]interface{} {
var json []map[string]interface{}
found := make(map[string]bool)
// Iterate over every json provided and check if it is already in the final json
// If it contains some invalid entry (equals nil), then skip that entry
for _, m := range maps {
for _, entry := range m {
if entry["names"] == nil && entry["Names"] == nil {
continue
}
key := entry[joinkey].(string)
if _, ok := found[key]; !ok {
found[key] = true
json = append(json, entry)
}
}
}
return json
}
func ShowManual(manual string) error {
manBinary, err := exec.LookPath("man")
if err != nil {