From 3c0bb1ed5aee2de1cd751838de87a009b9cac2d5 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Wed, 26 Jun 2024 01:30:56 -0500 Subject: [PATCH] fix(config): Handle newlines in `YAMPL_VALUE` env --- internal/config/values_hack.go | 5 +++++ internal/config/values_hack_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/internal/config/values_hack.go b/internal/config/values_hack.go index 119cf82..d3928c6 100644 --- a/internal/config/values_hack.go +++ b/internal/config/values_hack.go @@ -2,6 +2,7 @@ package config import ( "bufio" + "os" "strings" ) @@ -29,6 +30,10 @@ func FixStringToStringNewlines(s []string) []string { result = append(result, arg) } } + envName := EnvPrefix + strings.ToUpper(ValueFlag) + if env := os.Getenv(envName); env != "" { + _ = os.Setenv(envName, strings.ReplaceAll(env, "\n", ",")) + } return result } diff --git a/internal/config/values_hack_test.go b/internal/config/values_hack_test.go index 9fb8322..61a2009 100644 --- a/internal/config/values_hack_test.go +++ b/internal/config/values_hack_test.go @@ -1,12 +1,19 @@ package config import ( + "os" "testing" "github.com/stretchr/testify/assert" ) func TestFixStringToStringNewlines(t *testing.T) { + t.Run("env", func(t *testing.T) { + t.Setenv("YAMPL_VALUE", "a=a\nb=b") + FixStringToStringNewlines([]string{}) + assert.Equal(t, "a=a,b=b", os.Getenv("YAMPL_VALUE")) + }) + type args struct { s []string }