forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
58 lines (45 loc) · 1.34 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
54
55
56
57
58
package fileset
import (
"flag"
"fmt"
"strings"
"github.com/elastic/beats/libbeat/common"
)
// Modules related command line flags.
var (
modulesFlag = flag.String("modules", "", "List of enabled modules (comma separated)")
moduleOverrides = common.SettingFlag(nil, "M", "Module configuration overwrite")
)
type ModuleOverrides map[string]map[string]*common.Config // module -> fileset -> Config
// Get returns an array of configuration overrides that should be merged in order.
func (mo *ModuleOverrides) Get(module, fileset string) []*common.Config {
ret := []*common.Config{}
moduleWildcard := (*mo)["*"]["*"]
if moduleWildcard != nil {
ret = append(ret, moduleWildcard)
}
filesetWildcard := (*mo)[module]["*"]
if filesetWildcard != nil {
ret = append(ret, filesetWildcard)
}
cfg := (*mo)[module][fileset]
if cfg != nil {
ret = append(ret, cfg)
}
return ret
}
func getModulesCLIConfig() ([]string, *ModuleOverrides, error) {
modulesList := []string{}
if modulesFlag != nil {
modulesList = strings.Split(*modulesFlag, ",")
}
if moduleOverrides == nil {
return modulesList, nil, nil
}
var overrides ModuleOverrides
err := moduleOverrides.Unpack(&overrides)
if err != nil {
return []string{}, nil, fmt.Errorf("-M flags must be prefixed by the module and fileset: %v", err)
}
return modulesList, &overrides, nil
}