-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (43 loc) · 1.62 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
package main
import (
"fmt"
"os"
"path"
"github.com/gomatbase/go-log"
"github.com/rabobank/config-hub/cfg"
"github.com/rabobank/config-hub/server"
)
const usage = "config-hub v%s\n\n" +
"Usage:\n" +
" Server Mode:\n" +
" %s\n\n" +
" Credential Helper Mode:\n" +
" %s credentials <repo> <action>\n\n" +
" <action> = (get|store|erase) Only \"get\" is processed\n\n" +
" It will read from Stdin a series of key/pair values from input lines in the format <key>=<value>\n" +
" An empty line triggers end of input and will process the command with the provided values.\n" +
" Credentials are provided (if available) when \"host\" and \"protocol\" are read from Stdin, as expected\n" +
" from git credential helpers. Store and erase actions will read key/values from stdin but are NOPs.\n" +
" <repo> = The path component of the git repository url, this allows to fine tune the credentials requesst to\n" +
" specific repositories on the same host.\n"
func printUsage() int {
fmt.Printf("config-hub %s (%s)\n\n", cfg.Version, cfg.Commit)
name := path.Base(os.Args[0])
fmt.Printf(usage, cfg.Version, name, name)
return -1
}
func main() {
if len(os.Args) == 1 {
fmt.Printf("config-hub %s (%s)\n\n", cfg.Version, cfg.Commit)
fmt.Println("Logging level :", log.LevelName(cfg.LogLevel))
server.Server()
} else if len(os.Args) < 3 || os.Args[1] != "credentials" {
os.Exit(printUsage())
} else {
cfg.FinishCredentialsConfiguration()
if e := Credentials(); e != nil {
fmt.Println("error getting credentials", e)
os.Exit(printUsage())
}
}
}