-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
58 lines (48 loc) · 1.12 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
49
50
51
52
53
54
55
56
57
58
package genki
import (
"github.com/spf13/pflag"
)
const (
DefaultName = "genki"
HttpDebugPortConfigKey = "http-debug-port"
HttpDebugDisableConfigKey = "http-debug-disable"
)
type Options struct {
Name string
HttpDebugServerEnabled bool
HttpDebugServerPort string
}
func Name(name string) Option {
return func(opts *Options) {
opts.Name = name
}
}
func DisableDebugHttpServer() Option {
return func(opts *Options) {
opts.HttpDebugServerEnabled = false
}
}
func HttpDebugServerPort(port string) Option {
return func(opts *Options) {
if port != "" {
opts.HttpDebugServerPort = port
}
}
}
func newOptions(opts ...Option) Options {
opt := Options{
Name: DefaultName,
HttpDebugServerEnabled: true,
HttpDebugServerPort: "3000",
}
for _, o := range opts {
o(&opt)
}
return opt
}
func Flags() *pflag.FlagSet {
fs := pflag.NewFlagSet("genki", pflag.ContinueOnError)
fs.String(HttpDebugPortConfigKey, "3000", "the port on which the debug http server is listening")
fs.Bool(HttpDebugDisableConfigKey, false, "disable the http-debug server")
return fs
}