diff --git a/auditbeat/main_test.go b/auditbeat/main_test.go index f5ad8a4b069e..8b16fe63a583 100644 --- a/auditbeat/main_test.go +++ b/auditbeat/main_test.go @@ -35,7 +35,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/filebeat/cmd/generate.go b/filebeat/cmd/generate.go index 582038716a1e..1e5a4b1a819b 100644 --- a/filebeat/cmd/generate.go +++ b/filebeat/cmd/generate.go @@ -26,6 +26,7 @@ import ( "github.com/elastic/beats/v7/filebeat/generator/fields" "github.com/elastic/beats/v7/filebeat/generator/fileset" "github.com/elastic/beats/v7/filebeat/generator/module" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/common/cli" "github.com/elastic/elastic-agent-libs/paths" ) @@ -63,7 +64,9 @@ func genGenerateModuleCmd() *cobra.Command { } genModuleCmd.Flags().String("modules-path", defaultHomePath, "Path to modules directory") + cfgfile.AddAllowedBackwardsCompatibleFlag("modules-path") genModuleCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats") + cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats") return genModuleCmd } @@ -88,7 +91,9 @@ func genGenerateFilesetCmd() *cobra.Command { } genFilesetCmd.Flags().String("modules-path", defaultHomePath, "Path to modules directory") + cfgfile.AddAllowedBackwardsCompatibleFlag("modules-path") genFilesetCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats") + cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats") return genFilesetCmd } @@ -113,7 +118,9 @@ func genGenerateFieldsCmd() *cobra.Command { } genFieldsCmd.Flags().String("es-beats", defaultHomePath, "Path to Elastic Beats") + cfgfile.AddAllowedBackwardsCompatibleFlag("es-beats") genFieldsCmd.Flags().Bool("without-documentation", false, "Do not add description fields") + cfgfile.AddAllowedBackwardsCompatibleFlag("without-documentation") return genFieldsCmd } diff --git a/filebeat/cmd/root.go b/filebeat/cmd/root.go index 2420a03efdba..48e9c9d74bce 100644 --- a/filebeat/cmd/root.go +++ b/filebeat/cmd/root.go @@ -26,6 +26,7 @@ import ( "github.com/elastic/beats/v7/filebeat/fileset" "github.com/elastic/beats/v7/filebeat/include" "github.com/elastic/beats/v7/filebeat/input" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd" "github.com/elastic/beats/v7/libbeat/cmd/instance" @@ -49,7 +50,9 @@ func FilebeatSettings(moduleNameSpace string) instance.Settings { } runFlags := pflag.NewFlagSet(Name, pflag.ExitOnError) runFlags.AddGoFlag(flag.CommandLine.Lookup("once")) + cfgfile.AddAllowedBackwardsCompatibleFlag("once") runFlags.AddGoFlag(flag.CommandLine.Lookup("modules")) + cfgfile.AddAllowedBackwardsCompatibleFlag("modules") return instance.Settings{ RunFlags: runFlags, Name: Name, @@ -66,8 +69,10 @@ func FilebeatSettings(moduleNameSpace string) instance.Settings { func Filebeat(inputs beater.PluginFactory, settings instance.Settings) *cmd.BeatsRootCmd { command := cmd.GenRootCmdWithSettings(beater.New(inputs), settings) command.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("M")) + cfgfile.AddAllowedBackwardsCompatibleFlag("M") command.TestCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules")) command.SetupCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("modules")) + cfgfile.AddAllowedBackwardsCompatibleFlag("modules") command.AddCommand(cmd.GenModulesCmd(Name, "", buildModulesManager)) command.AddCommand(genGenerateCmd()) return command diff --git a/filebeat/main_test.go b/filebeat/main_test.go index ed0486d91cf1..b73c88438e6f 100644 --- a/filebeat/main_test.go +++ b/filebeat/main_test.go @@ -41,7 +41,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") fbCommand = fbcmd.Filebeat(inputs.Init, fbcmd.FilebeatSettings("")) fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/heartbeat/cmd/root.go b/heartbeat/cmd/root.go index fd95013c6fe0..a1f80a7cda71 100644 --- a/heartbeat/cmd/root.go +++ b/heartbeat/cmd/root.go @@ -22,6 +22,7 @@ import ( "github.com/elastic/beats/v7/heartbeat/beater" "github.com/elastic/beats/v7/heartbeat/include" + "github.com/elastic/beats/v7/libbeat/cfgfile" cmd "github.com/elastic/beats/v7/libbeat/cmd" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/ecs" @@ -81,6 +82,7 @@ func Initialize(settings instance.Settings) *cmd.BeatsRootCmd { ` setup.ResetFlags() setup.Flags().Bool(cmd.IndexManagementKey, false, "Setup all components related to Elasticsearch index management, including template, ilm policy and rollover alias") + cfgfile.AddAllowedBackwardsCompatibleFlag(cmd.IndexManagementKey) return rootCmd } diff --git a/heartbeat/main_test.go b/heartbeat/main_test.go index ac69e001dd3f..18cc332b63af 100644 --- a/heartbeat/main_test.go +++ b/heartbeat/main_test.go @@ -34,7 +34,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/libbeat/cfgfile/cfgfile.go b/libbeat/cfgfile/cfgfile.go index 518d3e3d1550..f19ecad04216 100644 --- a/libbeat/cfgfile/cfgfile.go +++ b/libbeat/cfgfile/cfgfile.go @@ -33,14 +33,15 @@ import ( // Evil package level globals var ( - once sync.Once - configfiles *config.StringsFlag - overwrites *config.C - defaults *config.C - homePath *string - configPath *string - dataPath *string - logsPath *string + once sync.Once + configfiles *config.StringsFlag + overwrites *config.C + defaults *config.C + homePath *string + configPath *string + dataPath *string + logsPath *string + allowedBackwardsCompatibleFlags []string ) func Initialize() { @@ -50,7 +51,9 @@ func Initialize() { // created. See ChangeDefaultCfgfileFlag which should // be called prior to flags.Parse(). configfiles = config.StringArrFlag(nil, "c", "beat.yml", "Configuration file, relative to path.config") + AddAllowedBackwardsCompatibleFlag("c") overwrites = config.SettingFlag(nil, "E", "Configuration overwrite") + AddAllowedBackwardsCompatibleFlag("E") defaults = config.MustNewConfigFrom(map[string]interface{}{ "path": map[string]interface{}{ "home": ".", // to be initialized by beat @@ -60,16 +63,36 @@ func Initialize() { }, }) homePath = config.ConfigOverwriteFlag(nil, overwrites, "path.home", "path.home", "", "Home path") + AddAllowedBackwardsCompatibleFlag("path.home") configPath = config.ConfigOverwriteFlag(nil, overwrites, "path.config", "path.config", "", "Configuration path") + AddAllowedBackwardsCompatibleFlag("path.config") dataPath = config.ConfigOverwriteFlag(nil, overwrites, "path.data", "path.data", "", "Data path") + AddAllowedBackwardsCompatibleFlag("path.data") logsPath = config.ConfigOverwriteFlag(nil, overwrites, "path.logs", "path.logs", "", "Logs path") + AddAllowedBackwardsCompatibleFlag("path.logs") }) } +func isAllowedBackwardsCompatibleFlag(f string) bool { + for _, existing := range allowedBackwardsCompatibleFlags { + if existing == f { + return true + } + } + return false +} + +func AddAllowedBackwardsCompatibleFlag(f string) { + if isAllowedBackwardsCompatibleFlag(f) { + return + } + allowedBackwardsCompatibleFlags = append(allowedBackwardsCompatibleFlags, f) +} + func ConvertFlagsForBackwardsCompatibility() { // backwards compatibility workaround, convert -flags to --flags: for i, arg := range os.Args[1:] { - if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 { + if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && isAllowedBackwardsCompatibleFlag(strings.TrimPrefix(arg, "-")) { os.Args[1+i] = "-" + arg } } diff --git a/libbeat/cmd/export/dashboard.go b/libbeat/cmd/export/dashboard.go index 7b878e00788b..4a4e13167f8c 100644 --- a/libbeat/cmd/export/dashboard.go +++ b/libbeat/cmd/export/dashboard.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/cobra" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/dashboards" "github.com/elastic/beats/v7/libbeat/version" @@ -101,8 +102,11 @@ func GenDashboardCmd(settings instance.Settings) *cobra.Command { } genTemplateConfigCmd.Flags().String("id", "", "Dashboard id") + cfgfile.AddAllowedBackwardsCompatibleFlag("id") genTemplateConfigCmd.Flags().String("yml", "", "Yaml file containing list of dashboard ID and filename pairs") + cfgfile.AddAllowedBackwardsCompatibleFlag("yml") genTemplateConfigCmd.Flags().String("folder", "", "Target folder to save exported assets") + cfgfile.AddAllowedBackwardsCompatibleFlag("folder") return genTemplateConfigCmd } diff --git a/libbeat/cmd/export/ilm_policy.go b/libbeat/cmd/export/ilm_policy.go index 60c97920fd79..557c62c8aaef 100644 --- a/libbeat/cmd/export/ilm_policy.go +++ b/libbeat/cmd/export/ilm_policy.go @@ -20,6 +20,7 @@ package export import ( "github.com/spf13/cobra" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/idxmgmt" "github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle" @@ -57,7 +58,9 @@ func GenGetILMPolicyCmd(settings instance.Settings) *cobra.Command { } genTemplateConfigCmd.Flags().String("es.version", settings.Version, "Elasticsearch version") + cfgfile.AddAllowedBackwardsCompatibleFlag("es.version") genTemplateConfigCmd.Flags().String("dir", "", "Specify directory for printing policy files. By default policies are printed to stdout.") + cfgfile.AddAllowedBackwardsCompatibleFlag("dir") return genTemplateConfigCmd } diff --git a/libbeat/cmd/export/index_pattern.go b/libbeat/cmd/export/index_pattern.go index 6b8b8c6839f6..863fc7a72cfe 100644 --- a/libbeat/cmd/export/index_pattern.go +++ b/libbeat/cmd/export/index_pattern.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/cobra" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/kibana" libversion "github.com/elastic/elastic-agent-libs/version" @@ -67,6 +68,7 @@ func GenIndexPatternConfigCmd(settings instance.Settings) *cobra.Command { } genTemplateConfigCmd.Flags().String("es.version", settings.Version, "Elasticsearch version") + cfgfile.AddAllowedBackwardsCompatibleFlag("es.version") return genTemplateConfigCmd } diff --git a/libbeat/cmd/export/template.go b/libbeat/cmd/export/template.go index ffd957961efe..45a83b986817 100644 --- a/libbeat/cmd/export/template.go +++ b/libbeat/cmd/export/template.go @@ -20,6 +20,7 @@ package export import ( "github.com/spf13/cobra" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/idxmgmt" "github.com/elastic/beats/v7/libbeat/idxmgmt/lifecycle" @@ -59,8 +60,11 @@ func GenTemplateConfigCmd(settings instance.Settings) *cobra.Command { } genTemplateConfigCmd.Flags().String("es.version", settings.Version, "Elasticsearch version") + cfgfile.AddAllowedBackwardsCompatibleFlag("es.version") genTemplateConfigCmd.Flags().Bool("noilm", false, "Generate template with ILM disabled") + cfgfile.AddAllowedBackwardsCompatibleFlag("noilm") genTemplateConfigCmd.Flags().String("dir", "", "Specify directory for printing template files. By default templates are printed to stdout.") + cfgfile.AddAllowedBackwardsCompatibleFlag("dir") return genTemplateConfigCmd } diff --git a/libbeat/cmd/keystore.go b/libbeat/cmd/keystore.go index 7f5ecd78c41b..34a1ccc5c220 100644 --- a/libbeat/cmd/keystore.go +++ b/libbeat/cmd/keystore.go @@ -29,6 +29,7 @@ import ( "github.com/spf13/cobra" tml "golang.org/x/crypto/ssh/terminal" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/common/cli" "github.com/elastic/beats/v7/libbeat/common/terminal" @@ -74,6 +75,7 @@ func genCreateKeystoreCmd(settings instance.Settings) *cobra.Command { }), } command.Flags().BoolVar(&flagForce, "force", false, "override the existing keystore") + cfgfile.AddAllowedBackwardsCompatibleFlag("force") return command } @@ -92,7 +94,9 @@ func genAddKeystoreCmd(settings instance.Settings) *cobra.Command { }), } command.Flags().BoolVar(&flagStdin, "stdin", false, "Use the stdin as the source of the secret") + cfgfile.AddAllowedBackwardsCompatibleFlag("stdin") command.Flags().BoolVar(&flagForce, "force", false, "Override the existing key") + cfgfile.AddAllowedBackwardsCompatibleFlag("force") return command } diff --git a/libbeat/cmd/root.go b/libbeat/cmd/root.go index 8566cced2323..cbe2f7f8f6e5 100644 --- a/libbeat/cmd/root.go +++ b/libbeat/cmd/root.go @@ -87,18 +87,30 @@ func GenRootCmdWithSettings(beatCreator beat.Creator, settings instance.Settings // Persistent flags, common across all subcommands rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("E")) + cfgfile.AddAllowedBackwardsCompatibleFlag("E") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("c")) + cfgfile.AddAllowedBackwardsCompatibleFlag("c") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("d")) + cfgfile.AddAllowedBackwardsCompatibleFlag("d") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("v")) + cfgfile.AddAllowedBackwardsCompatibleFlag("v") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("e")) + cfgfile.AddAllowedBackwardsCompatibleFlag("e") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("environment")) + cfgfile.AddAllowedBackwardsCompatibleFlag("environment") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.config")) + cfgfile.AddAllowedBackwardsCompatibleFlag("path.config") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.data")) + cfgfile.AddAllowedBackwardsCompatibleFlag("path.data") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.logs")) + cfgfile.AddAllowedBackwardsCompatibleFlag("path.logs") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.home")) + cfgfile.AddAllowedBackwardsCompatibleFlag("path.home") rootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("strict.perms")) + cfgfile.AddAllowedBackwardsCompatibleFlag("strict.perms") if f := flag.CommandLine.Lookup("plugin"); f != nil { rootCmd.PersistentFlags().AddGoFlag(f) + cfgfile.AddAllowedBackwardsCompatibleFlag("plugin") } // Inherit root flags from run command diff --git a/libbeat/cmd/run.go b/libbeat/cmd/run.go index b078aadaf89c..d6cadd318cee 100644 --- a/libbeat/cmd/run.go +++ b/libbeat/cmd/run.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" ) @@ -42,9 +43,13 @@ func genRunCmd(settings instance.Settings, beatCreator beat.Creator) *cobra.Comm // Run subcommand flags, only available to *beat run runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("N")) + cfgfile.AddAllowedBackwardsCompatibleFlag("N") runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("httpprof")) + cfgfile.AddAllowedBackwardsCompatibleFlag("httpprof") runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("cpuprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("cpuprofile") runCmd.Flags().AddGoFlag(flag.CommandLine.Lookup("memprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("memprofile") if settings.RunFlags != nil { runCmd.Flags().AddFlagSet(settings.RunFlags) diff --git a/libbeat/cmd/setup.go b/libbeat/cmd/setup.go index 64d1f41fdeaf..0b28d22f96f4 100644 --- a/libbeat/cmd/setup.go +++ b/libbeat/cmd/setup.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "github.com/elastic/beats/v7/libbeat/beat" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" ) @@ -111,11 +112,16 @@ func genSetupCmd(settings instance.Settings, beatCreator beat.Creator) *cobra.Co } setup.Flags().Bool(DashboardKey, false, "Setup dashboards") + cfgfile.AddAllowedBackwardsCompatibleFlag(DashboardKey) setup.Flags().Bool(PipelineKey, false, "Setup Ingest pipelines") + cfgfile.AddAllowedBackwardsCompatibleFlag(PipelineKey) setup.Flags().Bool(IndexManagementKey, false, "Setup all components related to Elasticsearch index management, including template, ilm policy and rollover alias") + cfgfile.AddAllowedBackwardsCompatibleFlag(IndexManagementKey) setup.Flags().Bool("enable-all-filesets", false, "Behave as if all modules and filesets had been enabled") + cfgfile.AddAllowedBackwardsCompatibleFlag("enable-all-filesets") setup.Flags().Bool("force-enable-module-filesets", false, "Behave as if all filesets, within enabled modules, are enabled") + cfgfile.AddAllowedBackwardsCompatibleFlag("force-enable-module-filesets") return &setup } diff --git a/libbeat/libbeat_test.go b/libbeat/libbeat_test.go index 6749376a73a3..1f9e1b3ffe8b 100644 --- a/libbeat/libbeat_test.go +++ b/libbeat/libbeat_test.go @@ -32,7 +32,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started diff --git a/metricbeat/cmd/root.go b/metricbeat/cmd/root.go index e3d308d2508c..497b71bed8ad 100644 --- a/metricbeat/cmd/root.go +++ b/metricbeat/cmd/root.go @@ -24,6 +24,7 @@ import ( "github.com/elastic/elastic-agent-libs/mapstr" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/ecs" @@ -61,6 +62,7 @@ func MetricbeatSettings(moduleNameSpace string) instance.Settings { } var runFlags = pflag.NewFlagSet(Name, pflag.ExitOnError) runFlags.AddGoFlag(flag.CommandLine.Lookup("system.hostfs")) + cfgfile.AddAllowedBackwardsCompatibleFlag("system.hostfs") return instance.Settings{ RunFlags: runFlags, Name: Name, diff --git a/metricbeat/main_test.go b/metricbeat/main_test.go index cd0c73e300ec..495ce5787e04 100644 --- a/metricbeat/main_test.go +++ b/metricbeat/main_test.go @@ -34,7 +34,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/packetbeat/cmd/root.go b/packetbeat/cmd/root.go index 7b1c20b34c6e..eb6d14b1692a 100644 --- a/packetbeat/cmd/root.go +++ b/packetbeat/cmd/root.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/pflag" + "github.com/elastic/beats/v7/libbeat/cfgfile" cmd "github.com/elastic/beats/v7/libbeat/cmd" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/libbeat/ecs" @@ -51,10 +52,15 @@ var RootCmd *cmd.BeatsRootCmd func PacketbeatSettings(globals processors.PluginConfig) instance.Settings { runFlags := pflag.NewFlagSet(Name, pflag.ExitOnError) runFlags.AddGoFlag(flag.CommandLine.Lookup("I")) + cfgfile.AddAllowedBackwardsCompatibleFlag("I") runFlags.AddGoFlag(flag.CommandLine.Lookup("t")) + cfgfile.AddAllowedBackwardsCompatibleFlag("t") runFlags.AddGoFlag(flag.CommandLine.Lookup("O")) + cfgfile.AddAllowedBackwardsCompatibleFlag("O") runFlags.AddGoFlag(flag.CommandLine.Lookup("l")) + cfgfile.AddAllowedBackwardsCompatibleFlag("l") runFlags.AddGoFlag(flag.CommandLine.Lookup("dump")) + cfgfile.AddAllowedBackwardsCompatibleFlag("dump") return instance.Settings{ RunFlags: runFlags, diff --git a/packetbeat/main_test.go b/packetbeat/main_test.go index e859028971f2..2dfcfb4572c5 100644 --- a/packetbeat/main_test.go +++ b/packetbeat/main_test.go @@ -34,7 +34,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/winlogbeat/main_test.go b/winlogbeat/main_test.go index d0ffa9518802..002c7431f99a 100644 --- a/winlogbeat/main_test.go +++ b/winlogbeat/main_test.go @@ -33,7 +33,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // TestSystem is the function called when the test binary is started. diff --git a/x-pack/agentbeat/main_test.go b/x-pack/agentbeat/main_test.go index d3b021283740..b03331b4b52a 100644 --- a/x-pack/agentbeat/main_test.go +++ b/x-pack/agentbeat/main_test.go @@ -23,7 +23,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") abCommand = AgentBeat() abCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") abCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/auditbeat/main_test.go b/x-pack/auditbeat/main_test.go index ecce28993f7c..3456231f5167 100644 --- a/x-pack/auditbeat/main_test.go +++ b/x-pack/auditbeat/main_test.go @@ -22,7 +22,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/filebeat/main_test.go b/x-pack/filebeat/main_test.go index e5a917520fb0..71b32b9e6e86 100644 --- a/x-pack/filebeat/main_test.go +++ b/x-pack/filebeat/main_test.go @@ -25,7 +25,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") fbCommand = fbcmd.Filebeat() fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") fbCommand.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/functionbeat/main_test.go b/x-pack/functionbeat/main_test.go index 3191d5265604..1c21f88e2891 100644 --- a/x-pack/functionbeat/main_test.go +++ b/x-pack/functionbeat/main_test.go @@ -22,7 +22,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/functionbeat/provider/aws/cmd/root.go b/x-pack/functionbeat/provider/aws/cmd/root.go index fc7a7e0c2515..c8e7ba17d62b 100644 --- a/x-pack/functionbeat/provider/aws/cmd/root.go +++ b/x-pack/functionbeat/provider/aws/cmd/root.go @@ -7,6 +7,7 @@ package cmd import ( "flag" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/x-pack/functionbeat/function/beater" funcmd "github.com/elastic/beats/v7/x-pack/functionbeat/function/cmd" ) @@ -20,6 +21,9 @@ var RootCmd *funcmd.FunctionCmd func init() { RootCmd = funcmd.NewFunctionCmd(Name, beater.New) RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("d")) + cfgfile.AddAllowedBackwardsCompatibleFlag("d") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("v")) + cfgfile.AddAllowedBackwardsCompatibleFlag("v") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("e")) + cfgfile.AddAllowedBackwardsCompatibleFlag("e") } diff --git a/x-pack/functionbeat/provider/aws/main_test.go b/x-pack/functionbeat/provider/aws/main_test.go index ea0c47319af6..f180fd28275d 100644 --- a/x-pack/functionbeat/provider/aws/main_test.go +++ b/x-pack/functionbeat/provider/aws/main_test.go @@ -21,7 +21,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/functionbeat/provider/local/main_test.go b/x-pack/functionbeat/provider/local/main_test.go index ec8b5228b19a..7c617b300a65 100644 --- a/x-pack/functionbeat/provider/local/main_test.go +++ b/x-pack/functionbeat/provider/local/main_test.go @@ -21,7 +21,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/heartbeat/main_test.go b/x-pack/heartbeat/main_test.go index b64eb1b33e30..44d5882a9905 100644 --- a/x-pack/heartbeat/main_test.go +++ b/x-pack/heartbeat/main_test.go @@ -20,7 +20,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/libbeat/libbeat_test.go b/x-pack/libbeat/libbeat_test.go index 338ebd7e5fbd..a3df546f3f38 100644 --- a/x-pack/libbeat/libbeat_test.go +++ b/x-pack/libbeat/libbeat_test.go @@ -8,6 +8,7 @@ import ( "flag" "testing" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/tests/system/template" ) @@ -18,11 +19,14 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started func TestSystem(t *testing.T) { + cfgfile.ConvertFlagsForBackwardsCompatibility() if *systemTest { main() } diff --git a/x-pack/metricbeat/main_test.go b/x-pack/metricbeat/main_test.go index 7f901cad1aa4..e96a9932765c 100644 --- a/x-pack/metricbeat/main_test.go +++ b/x-pack/metricbeat/main_test.go @@ -19,7 +19,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/osquerybeat/main_test.go b/x-pack/osquerybeat/main_test.go index dc54c98f7e0c..30a9b88efb64 100644 --- a/x-pack/osquerybeat/main_test.go +++ b/x-pack/osquerybeat/main_test.go @@ -21,7 +21,9 @@ func init() { systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/packetbeat/main_test.go b/x-pack/packetbeat/main_test.go index 82f076848475..a332f5c99353 100644 --- a/x-pack/packetbeat/main_test.go +++ b/x-pack/packetbeat/main_test.go @@ -19,7 +19,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main. diff --git a/x-pack/winlogbeat/cmd/export.go b/x-pack/winlogbeat/cmd/export.go index 54f9f02e18c8..facd2fb0e929 100644 --- a/x-pack/winlogbeat/cmd/export.go +++ b/x-pack/winlogbeat/cmd/export.go @@ -10,6 +10,7 @@ import ( "github.com/spf13/cobra" + "github.com/elastic/beats/v7/libbeat/cfgfile" "github.com/elastic/beats/v7/libbeat/cmd/instance" "github.com/elastic/beats/v7/winlogbeat/module" libversion "github.com/elastic/elastic-agent-libs/version" @@ -48,7 +49,9 @@ func GenExportPipelineCmd(settings instance.Settings) *cobra.Command { } genExportPipelineCmd.Flags().String("es.version", settings.Version, "Elasticsearch version (required)") + cfgfile.AddAllowedBackwardsCompatibleFlag("es.version") genExportPipelineCmd.Flags().String("dir", "", "Specify directory for exporting pipelines. Default is current directory.") + cfgfile.AddAllowedBackwardsCompatibleFlag("dir") return genExportPipelineCmd } diff --git a/x-pack/winlogbeat/main_test.go b/x-pack/winlogbeat/main_test.go index 1d4fbd8e7a92..b4c0f3b124a1 100644 --- a/x-pack/winlogbeat/main_test.go +++ b/x-pack/winlogbeat/main_test.go @@ -19,7 +19,9 @@ func init() { testing.Init() systemTest = flag.Bool("systemTest", false, "Set to true when running system tests") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("systemTest")) + cfgfile.AddAllowedBackwardsCompatibleFlag("systemTest") cmd.RootCmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("test.coverprofile")) + cfgfile.AddAllowedBackwardsCompatibleFlag("test.coverprofile") } // Test started when the test binary is started. Only calls main.