-
Notifications
You must be signed in to change notification settings - Fork 30
/
main.go
65 lines (50 loc) · 1.68 KB
/
main.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
61
62
63
64
65
package main
import (
"fmt"
"os"
"github.com/aws-cloudformation/rain/cfn/format"
"github.com/aws-cloudformation/rain/cfn/spec/builder"
//Drop-in replacement for flag that supports POSIX style flags
flag "github.com/spf13/pflag"
)
const usage = `Usage: cfn-skeleton [OPTIONS] [RESOURCE TYPES...]
cfn-skeleton is a tool that generates skeleton CloudFormation templates
containing definitions for the resource types that you specify.
You can use a short name for a resource type so long as it is unambiguous.
For example 'Bucket', 'S3::Bucket', and 'AWS::S3::Bucket' refer to the same type.
But 'Instance' would need disambiguation.
Options:
-b, --bare Produce a minimal template, omitting all optional resource properties.
-i, --iam If any resource includes an IAM policy definition, populate that too.
-j, --json Output the template in JSON format (default: YAML).
--help Show this message and exit.
`
var bareFlag bool
var jsonFlag bool
func init() {
flag.BoolVarP(&bareFlag, "bare", "b", false, "Produce a minimal template, omitting all optional resource properties.")
flag.BoolVarP(&jsonFlag, "json", "j", false, "Output the template in JSON format (default: YAML).")
}
func die() {
fmt.Fprint(os.Stderr, usage)
os.Exit(1)
}
func main() {
flag.Parse()
//Get whatever's left after the flags have been parsed
resourceTypes := flag.Args()
if len(resourceTypes) == 0 {
die()
}
resources := resolveResources(resourceTypes)
//build the template
b := builder.NewCfnBuilder(!bareFlag, true)
t, c := b.Template(resources)
options := format.Options{
Comments: c,
}
if jsonFlag {
options.Style = format.JSON
}
fmt.Println(format.Template(t, options))
}