-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathalias.go
42 lines (39 loc) · 1014 Bytes
/
alias.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
)
func runAlias(inventory Inventory) (errs int) {
i := 0
fmt.Printf("# Tagging Aliases\n\n")
for _, image := range inventory["images"] {
name := image["name"].(string)
aliases := getAliasArray(image)
for _, alias := range aliases {
fmt.Printf("%v. %v -> %v\n", i, name, alias)
i++
output, err := dockerAlias(name, alias)
if err != nil {
fmt.Printf("Error creating tag:\n\n```\n%v\n```\n\n%v\n", output, err)
errs++
}
}
}
fmt.Printf("\n")
return
}
func getAliasArray(image map[string]interface{}) (aliases []string) {
switch image["alias"].(type) {
case string:
// If the value is a single string, append it to the array and be done
aliases = append(aliases, image["alias"].(string))
break
case []interface{}:
// If the value is an array, iterate through and add all of the strings
// to the array one by one.
for _, str := range image["alias"].([]interface{}) {
aliases = append(aliases, str.(string))
}
break
}
return
}