-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
62 lines (50 loc) · 1.54 KB
/
config.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
package main
import (
"log"
"os"
"strings"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
type appConfig struct {
listenAddress string
githubUserURL string
importDomain string
}
func parseFlags(args []string) appConfig {
config := appConfig{}
app := kingpin.New("go-importd", "Redirector for go imports for custom domains.")
app.Writer(os.Stdout)
app.HelpFlag.Short('h')
app.Author("Christian Höltje https://docwhat.org/")
app.Version(versionString())
app.VersionFlag.Short('v')
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Unable to get hostname: %s", err)
}
app.Flag("listen", "The address to serve HTTP on. (Env: GO_IMPORTD_LISTEN)").
Short('l').
Default(":http").
OverrideDefaultFromEnvar("GO_IMPORTD_LISTEN").
StringVar(&config.listenAddress)
app.Flag("import-domain", "The domain for imports. Usually this hostname. (Env: GO_IMPORTD_IMPORT_DOMAIN)").
Short('i').
Default(hostname).
OverrideDefaultFromEnvar("GO_IMPORTD_IMPORT_DOMAIN").
StringVar(&config.importDomain)
app.Flag("github-user-url", "The base URL on github for your projects. (Env: GO_IMPORTD_GITHUB_USER_URL)").
Short('g').
Default("https://github.com/docwhat").
OverrideDefaultFromEnvar("GO_IMPORTD_GITHUB_USER_URL").
StringVar(&config.githubUserURL)
if command, err := app.Parse(args); err != nil {
app.Usage(nil)
} else {
if command != "" {
app.Usage(nil)
}
}
config.githubUserURL = strings.TrimSuffix(config.githubUserURL, "/") + "/"
config.importDomain = strings.TrimSuffix(config.importDomain, "/") + "/"
return config
}