-
Notifications
You must be signed in to change notification settings - Fork 308
/
options.go
48 lines (42 loc) · 1.33 KB
/
options.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 app
import (
"flag"
"os"
)
// Options contains application's initialisation options
type Options struct {
NormalMode bool
DegradedMode bool
ClearDB bool
Cpuprofile string
Memprofile string
VersionFlag bool
EnterpriseToken string
}
// LoadOptions loads application's initialisation options based on command line flags and environment
func LoadOptions(args []string) *Options {
flagSet := flag.NewFlagSet(args[0], flag.ExitOnError)
// Parse command line options
normalMode := flagSet.Bool("normal-mode", false, "a bool")
degradedMode := flagSet.Bool("degraded-mode", false, "a bool")
clearDB := flagSet.Bool("cleardb", false, "a bool")
cpuprofile := flagSet.String("cpuprofile", "", "write cpu profile to `file`")
memprofile := flagSet.String("memprofile", "", "write memory profile to `file`")
versionFlag := flagSet.Bool("v", false, "Print the current version and exit")
serverMode := os.Getenv("RSERVER_MODE")
if serverMode == "normal" {
*normalMode = true
} else if serverMode == "degraded" {
*degradedMode = true
}
// Ignore errors; flagSet is set for ExitOnError.
_ = flagSet.Parse(args[1:])
return &Options{
NormalMode: *normalMode,
DegradedMode: *degradedMode,
ClearDB: *clearDB,
Cpuprofile: *cpuprofile,
Memprofile: *memprofile,
VersionFlag: *versionFlag,
}
}