diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index df3a71416b6..3ac6691ef1a 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -977,6 +977,12 @@ func (b *Beat) Setup(settings Settings, bt beat.Creator, setup SetupSettings) er // handleFlags parses the command line flags. It invokes the HandleFlags // callback if implemented by the Beat. func (b *Beat) handleFlags() error { + // backwards compatibility workaround, convert -flags to --flags: + for i, arg := range os.Args[1:] { + if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 { + os.Args[1+i] = "-" + arg + } + } flag.Parse() return cfgfile.HandleFlags() } diff --git a/libbeat/cmd/root.go b/libbeat/cmd/root.go index 671b72fde1e..d7eb1d9bca2 100644 --- a/libbeat/cmd/root.go +++ b/libbeat/cmd/root.go @@ -21,7 +21,6 @@ import ( "flag" "fmt" "os" - "strings" "github.com/spf13/cobra" @@ -33,15 +32,6 @@ import ( "github.com/elastic/beats/v7/libbeat/outputs/elasticsearch" ) -func init() { - // backwards compatibility workaround, convert -flags to --flags: - for i, arg := range os.Args[1:] { - if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") && len(arg) > 2 { - os.Args[1+i] = "-" + arg - } - } -} - // BeatsRootCmd handles all application command line interface, parses user // flags and runs subcommands type BeatsRootCmd struct {