From 38921f9c5a2619abaee4c8ab63a2fdc8dde0be51 Mon Sep 17 00:00:00 2001 From: Erik Baranowski <39704712+erikbaranowski@users.noreply.github.com> Date: Fri, 15 Dec 2023 15:20:26 -0500 Subject: [PATCH] fix for static mode extra-args (#5989) Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com> --- cmd/internal/flowmode/cmd_convert.go | 10 ++++++++-- cmd/internal/flowmode/cmd_convert_test.go | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/internal/flowmode/cmd_convert.go b/cmd/internal/flowmode/cmd_convert.go index bb7f11cc9c61..01e03a08002e 100644 --- a/cmd/internal/flowmode/cmd_convert.go +++ b/cmd/internal/flowmode/cmd_convert.go @@ -195,7 +195,7 @@ func parseExtraArgs(extraArgs string) ([]string, error) { } arguments := strings.Fields(extraArgs) - for _, arg := range arguments { + for i, arg := range arguments { fs := pflag.NewFlagSet("extra-args", pflag.ExitOnError) fs.ParseErrorsWhitelist.UnknownFlags = true keyStartIndex := 0 @@ -226,7 +226,13 @@ func parseExtraArgs(extraArgs string) ([]string, error) { if keyStartIndex == 2 { fs.StringVar(&result[lastIndex], key, result[lastIndex], "") } else { - fs.StringVarP(&result[lastIndex], "", key, result[lastIndex], "") + // static mode uses keys with a single dash. We need to sanitize them here. + if len(key) != 1 { + arguments[i] = "-" + arguments[i] + fs.StringVar(&result[lastIndex], key, result[lastIndex], "") + } else { + fs.StringVarP(&result[lastIndex], "", key, result[lastIndex], "") + } } // We must parse the flag here because the pointer to the array element diff --git a/cmd/internal/flowmode/cmd_convert_test.go b/cmd/internal/flowmode/cmd_convert_test.go index 571ea3667326..4871a8d2b977 100644 --- a/cmd/internal/flowmode/cmd_convert_test.go +++ b/cmd/internal/flowmode/cmd_convert_test.go @@ -15,6 +15,11 @@ func TestParseExtraArgs(t *testing.T) { } var testCases = []testCase{ + { + name: "integrations next with env vars", + extraArgs: "-enable-features=integrations-next -config.expand-env", + expected: []string{"-enable-features", "integrations-next", "-config.expand-env"}, + }, { name: "longhand", extraArgs: "--key=value",