This repository has been archived by the owner on Sep 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (77 loc) · 2.11 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"os"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
func main() {
exit := func(err error) {
if err != nil {
log.Fatal(err)
}
}
app := cli.NewApp()
app.Author = "marvin + konsorten GmbH"
app.Version = versionString
app.HideHelp = true
app.Usage = `Consul Versioning Tool
This tool updates a Consul configuration based on a git repository
by handling the committed files.
The following file structure is supported:
<git repository root>
+- rootkey.subkey (key directory)
+- index.yml (properties file)
+- example.json (value file)
+- example2.jpg (value file)
Every directory is interpreted as a folder in Consul. The directory
name is allowed to contain dots to match several subfolders.
Every file in a directory is interpreted as key-value where
the key is the filename and the value is the contents of the file.
The filename is not allowed to contain dots.
The properties file is a special file named "index.yml" and is
parsed to contain several properties at once. It has the following
format:
properties:
mykey1: "simple value"
mykey2.subkey: "folder with value"
mykey3: |
multi-line value
(including all newlines)
mykey4: >
multi-line value
(removing all newlines)
`
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "directory, C",
Value: ".",
Usage: "The Git repository directory to use. Using the current as default.",
},
cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug output.",
},
}
app.Action = func(c *cli.Context) {
exit(run(c))
}
exit(app.Run(os.Args))
}
func run(c *cli.Context) error {
// enable debug output
initTerminal()
if c.Bool("debug") {
log.SetLevel(log.DebugLevel)
}
// run in remote mode?
remote := c.String("repository")
if remote != "" {
log.Infof("Git repository URL: %v", remote)
return runRemoteRepository(remote)
}
// run in directory mode?
dir := c.String("directory")
log.Infof("Git repository directory: %v", dir)
// start handling the directory
return runLocalRepository(dir)
}