Skip to content

Commit

Permalink
init configuration with settings in export commands too (#8684)
Browse files Browse the repository at this point in the history
  • Loading branch information
graphaelli committed Oct 23, 2018
1 parent 8cc6e9f commit bb915ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
7 changes: 4 additions & 3 deletions libbeat/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ import (
"github.com/spf13/cobra"

"github.com/elastic/beats/libbeat/cmd/export"
"github.com/elastic/beats/libbeat/cmd/instance"
)

func genExportCmd(name, idxPrefix, beatVersion string) *cobra.Command {
func genExportCmd(settings instance.Settings, name, idxPrefix, beatVersion string) *cobra.Command {
exportCmd := &cobra.Command{
Use: "export",
Short: "Export current config or index template",
}

exportCmd.AddCommand(export.GenExportConfigCmd(name, idxPrefix, beatVersion))
exportCmd.AddCommand(export.GenTemplateConfigCmd(name, idxPrefix, beatVersion))
exportCmd.AddCommand(export.GenExportConfigCmd(settings, name, idxPrefix, beatVersion))
exportCmd.AddCommand(export.GenTemplateConfigCmd(settings, name, idxPrefix, beatVersion))
exportCmd.AddCommand(export.GenDashboardCmd(name, idxPrefix, beatVersion))

return exportCmd
Expand Down
8 changes: 4 additions & 4 deletions libbeat/cmd/export/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ import (
)

// GenExportConfigCmd write to stdout the current configuration in the YAML format.
func GenExportConfigCmd(name, idxPrefix, beatVersion string) *cobra.Command {
func GenExportConfigCmd(settings instance.Settings, name, idxPrefix, beatVersion string) *cobra.Command {
return &cobra.Command{
Use: "config",
Short: "Export current config to stdout",
Run: cli.RunWith(func(cmd *cobra.Command, args []string) error {
return exportConfig(name, idxPrefix, beatVersion)
return exportConfig(settings, name, idxPrefix, beatVersion)
}),
}
}

func exportConfig(name, idxPrefix, beatVersion string) error {
func exportConfig(settings instance.Settings, name, idxPrefix, beatVersion string) error {
b, err := instance.NewBeat(name, idxPrefix, beatVersion)
if err != nil {
return fmt.Errorf("error initializing beat: %s", err)
}

err = b.Init()
err = b.InitWithSettings(settings)
if err != nil {
return fmt.Errorf("error initializing beat: %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions libbeat/cmd/export/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/elastic/beats/libbeat/template"
)

func GenTemplateConfigCmd(name, idxPrefix, beatVersion string) *cobra.Command {
func GenTemplateConfigCmd(settings instance.Settings, name, idxPrefix, beatVersion string) *cobra.Command {
genTemplateConfigCmd := &cobra.Command{
Use: "template",
Short: "Export index template to stdout",
Expand All @@ -42,7 +42,7 @@ func GenTemplateConfigCmd(name, idxPrefix, beatVersion string) *cobra.Command {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
}
err = b.Init()
err = b.InitWithSettings(settings)
if err != nil {
fmt.Fprintf(os.Stderr, "Error initializing beat: %s\n", err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func GenRootCmdWithSettings(beatCreator beat.Creator, settings instance.Settings
rootCmd.SetupCmd = genSetupCmd(name, indexPrefix, version, beatCreator)
rootCmd.VersionCmd = genVersionCmd(name, version)
rootCmd.CompletionCmd = genCompletionCmd(name, version, rootCmd)
rootCmd.ExportCmd = genExportCmd(name, indexPrefix, version)
rootCmd.ExportCmd = genExportCmd(settings, name, indexPrefix, version)
rootCmd.TestCmd = genTestCmd(name, version, beatCreator)
rootCmd.KeystoreCmd = genKeystoreCmd(name, indexPrefix, version, runFlags)

Expand Down

0 comments on commit bb915ac

Please sign in to comment.