forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 9
/
flags.go
36 lines (29 loc) · 941 Bytes
/
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
package beat
// FlagsHandler is an interface that can optionally be implemented by a Beat
// if it needs to process command line flags on startup. If implemented, the
// HandleFlags method will be invoked after parsing the command line flags
// and before any of the Beater interface methods are invoked. There will be
// no callback when '-help' or '-version' are specified.
type FlagsHandler interface {
HandleFlags(*Beat) error // Handle any custom command line arguments.
}
type FlagsHandlerCallback func(*Beat) error
var handlers []FlagsHandler
func AddFlagsHandler(h FlagsHandler) {
handlers = append(handlers, h)
}
func AddFlagsCallback(cb func(*Beat) error) {
AddFlagsHandler(FlagsHandlerCallback(cb))
}
func handleFlags(b *Beat) error {
for _, h := range handlers {
err := h.HandleFlags(b)
if err != nil {
return err
}
}
return nil
}
func (cb FlagsHandlerCallback) HandleFlags(b *Beat) error {
return cb(b)
}