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:
		
							parent
							
								
									6170f494aa
								
							
						
					
					
						commit
						928bf53943
					
				| 
						 | 
				
			
			@ -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 {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue