-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
68 lines (59 loc) · 2.14 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
66
67
68
package main
import (
"fmt"
"os"
"flag"
"io"
"github.com/alistanis/cf_parameter_generator/lib"
)
var (
inFile string
outFile string
min bool
numIndentSpaces int
overwrite bool
removeOldParamsNotInTemplate bool
oyaml bool
inyaml bool
verbose bool
printVersion bool
)
const (
version = "cf_parameter_generator: v1.9"
)
func init() {
flag.StringVar(&inFile, "f", "", "The file to read from to generate parameters.")
flag.StringVar(&outFile, "o", "", "Optional: Specify a file name to write out parameters.")
flag.BoolVar(&min, "min", false, "If given, will generate minified output.")
flag.IntVar(&numIndentSpaces, "spaces", 2, "The number of spaces used to indent the file if not generating minified output.")
flag.BoolVar(&overwrite, "overwrite", false, "By default, will update an existing parameters file with newly found parameters, but will not overwrite.")
flag.BoolVar(&removeOldParamsNotInTemplate, "r", false, "Removes old entries from parameters found in old parameters files.")
flag.BoolVar(&oyaml, "outyaml", false, "Will output in yaml instead of json.")
flag.BoolVar(&inyaml, "inyaml", false, "Will expect input as yaml instead of json.")
flag.BoolVar(&verbose, "v", false, "Places verbose output in the ParameterValue field to be replaced.")
flag.BoolVar(&printVersion, "version", false, "Print the version and exits.")
flag.Parse()
if printVersion {
fmt.Println(version)
os.Exit(0)
}
}
func config() *cfpgen.Config {
return &cfpgen.Config{InFile: inFile, OutFile: outFile, Minimize: min, Indent: numIndentSpaces, Overwrite: overwrite, RemoveOldParamsNotInTemplate: removeOldParamsNotInTemplate, OutYaml: oyaml, InYaml: inyaml, Verbose: verbose}
}
func main() {
var reader io.Reader
stat, err := os.Stdin.Stat()
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
if (stat.Mode() & os.ModeCharDevice) == 0 {
reader = os.Stdin
}
err = cfpgen.Generate(config(), reader)
if err != nil {
fmt.Fprintln(os.Stderr, err)
flag.Usage()
os.Exit(-1)
}
}