-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
85 lines (71 loc) · 1.79 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"os"
"strings"
"github.com/One-com/gonelog/log"
"gopkg.in/urfave/cli.v1"
)
const (
defaultDelims = "{{:}}"
)
var (
// Version generated from Makefile
VERSION string
stdOutFlag = cli.BoolFlag{
Name: "stdout",
Usage: "forces output to be written to stdout",
Destination: &forceStdOutFlag,
}
logLevelFlag = cli.IntFlag{
Name: "log-level",
Value: 4,
Usage: "log level to emit to the screen",
Destination: &logLevel,
}
forceFlag = cli.BoolFlag{
Name: "no-overwrite",
Usage: "do not overwrite destination file if it already exists",
Destination: &noOverwriteFlag,
}
delimsFlag = cli.StringFlag{
Name: "delims",
Usage: `template tag delimiters. Default "{{":"}}"`,
Value: defaultDelims,
Destination: &rawDelims,
}
renderCommand = cli.Command{
Action: renderCmd,
Name: "render",
Usage: "renders the specified definition file(s)",
ArgsUsage: "[definition]",
}
app = cli.NewApp()
rawDelims string
delims = strings.Split(defaultDelims, ":")
noOverwriteFlag bool
forceStdOutFlag bool
logLevel int
l = log.New(os.Stdout, "", log.Lcolor|log.Ldate|log.Ltime|log.Llevel)
)
func init() {
app.Name = "docker-templates"
app.Usage = "render Docker Compose / Stack file templates with the power of go templates"
app.Version = VERSION
app.Flags = []cli.Flag{
stdOutFlag,
delimsFlag,
logLevelFlag,
}
app.Commands = []cli.Command{renderCommand}
if rawDelims != "" {
delims := strings.Split(rawDelims, ":")
if len(delims) != 2 {
l.Panicf("Bad delimiters argument: %s. Expected \"left:right\"", delims)
}
}
}
func main() {
if err := app.Run(os.Args); err != nil {
l.Panicf("Error found! Aborting execution: %s", err)
}
}