forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
45 lines (38 loc) · 985 Bytes
/
config.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
package export
import (
"fmt"
"os"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"github.com/elastic/beats/libbeat/cmd/instance"
)
func GenExportConfigCmd(name, idxPrefix, beatVersion string) *cobra.Command {
return &cobra.Command{
Use: "config",
Short: "Export current config to stdout",
Run: func(cmd *cobra.Command, args []string) {
b, err := instance.NewBeat(name, idxPrefix, beatVersion)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}
err = b.Init()
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}
var config map[string]interface{}
err = b.RawConfig.Unpack(&config)
if err != nil {
fmt.Fprintf(os.Stderr, "Error unpacking config")
os.Exit(1)
}
res, err := yaml.Marshal(config)
if err != nil {
fmt.Fprintf(os.Stderr, "Error converting config to YAML format")
os.Exit(1)
}
os.Stdout.Write(res)
},
}
}