-
Notifications
You must be signed in to change notification settings - Fork 30
/
util.go
60 lines (48 loc) · 1.21 KB
/
util.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"os"
"sort"
"strings"
"github.com/aws-cloudformation/rain/cfn/spec"
)
func resolveType(suffix string) string {
options := spec.Cfn.ResolveResource(suffix)
if len(options) == 0 {
fmt.Fprintf(os.Stderr, "No resource type found matching '%s'\n", suffix)
os.Exit(1)
} else if len(options) != 1 {
fmt.Fprintf(os.Stderr, "Ambiguous resource type '%s'; could be any of:\n", suffix)
sort.Strings(options)
for _, option := range options {
fmt.Fprintf(os.Stderr, " %s\n", option)
}
os.Exit(1)
}
return options[0]
}
func makeName(resourceType string) string {
parts := strings.Split(resourceType, "::")
return "My" + parts[len(parts)-1]
}
func resolveResources(resourceTypes []string) map[string]string {
resources := make(map[string]string)
for _, r := range resourceTypes {
r = resolveType(r)
name := makeName(r)
if _, ok := resources[name]; ok {
resources[name+"1"] = resources[name]
delete(resources, name)
name = name + "2"
} else if _, ok := resources[name+"1"]; ok {
for i := 2; true; i++ {
if _, ok := resources[name+fmt.Sprint(i)]; !ok {
name = name + fmt.Sprint(i)
break
}
}
}
resources[name] = r
}
return resources
}