/
flags.go
53 lines (46 loc) · 1.16 KB
/
flags.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
package app
import "strings"
const (
DefaultEnvoyConfigPath = "C:\\etc\\cf-assets\\envoy_config\\envoy.yaml"
DefaultSdsCertAndKeysPath = "C:\\etc\\cf-assets\\envoy_config\\sds-server-cert-and-key.yaml"
DefaultSdsValidationContextPath = "C:\\etc\\cf-assets\\envoy_config\\sds-server-validation-context.yaml"
)
type Options struct {
EnvoyConfig string
SdsCreds string
SdsValidation string
}
type Flags struct {
options Options
}
func NewFlags() Flags {
return Flags{
options: Options{
EnvoyConfig: DefaultEnvoyConfigPath,
SdsCreds: DefaultSdsCertAndKeysPath,
SdsValidation: DefaultSdsValidationContextPath,
},
}
}
func (f Flags) Parse(args []string) Options {
for i, arg := range args {
switch arg {
case "-c":
if hasValidArgument(i, args) {
f.options.EnvoyConfig = args[i+1]
}
case "--creds":
if hasValidArgument(i, args) {
f.options.SdsCreds = args[i+1]
}
case "--validation":
if hasValidArgument(i, args) {
f.options.SdsValidation = args[i+1]
}
}
}
return f.options
}
func hasValidArgument(i int, args []string) bool {
return (i+1) < len(args) && !strings.HasPrefix(args[i+1], "-")
}