forked from rabobank/config-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (46 loc) · 1.71 KB
/
main.go
File metadata and controls
51 lines (46 loc) · 1.71 KB
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
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() {
switch true {
case 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()
case len(os.Args) == 2 && os.Args[1] == "version":
fmt.Println(cfg.Version)
case len(os.Args) < 3 || os.Args[1] != "credentials":
os.Exit(printUsage())
default:
cfg.FinishCredentialsConfiguration()
if e := Credentials(); e != nil {
fmt.Println("error getting credentials", e)
os.Exit(printUsage())
}
}
}