Skip to content

Commit

Permalink
Allow to use = in the actual variable definition (#208)
Browse files Browse the repository at this point in the history
Signed-off-by: tomasmik <tomasmik@protonmail.com>
  • Loading branch information
tomasmik authored Dec 22, 2023
1 parent 584b691 commit 5d9039b
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions internal/cmd/stack/local_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,35 +148,34 @@ type EnvironmentVariable struct {
Value graphql.String `json:"value"`
}

func parseEnvVariablesForLocalPreview(cliCtx *cli.Context) ([]EnvironmentVariable, error) {
envVars := make([]EnvironmentVariable, 0)

parseFn := func(ev string, mutateKey func(string) string) error {
parts := strings.Split(ev, "=")
if len(parts) != 2 {
return fmt.Errorf("invalid environment variable %q, must be in the form of KEY=VALUE", ev)
}
func parseEnvVar(env string, envVars []EnvironmentVariable, mutateKey func(string) string) ([]EnvironmentVariable, error) {
parts := strings.SplitN(env, "=", 2)
if len(parts) != 2 {
return envVars, fmt.Errorf("invalid environment variable %q, must be in the form of KEY=VALUE", env)
}

if mutateKey != nil {
parts[0] = mutateKey(parts[0])
}
if mutateKey != nil {
parts[0] = mutateKey(parts[0])
}

envVars = append(envVars, EnvironmentVariable{
Key: graphql.String(parts[0]),
Value: graphql.String(parts[1]),
})
return append(envVars, EnvironmentVariable{
Key: graphql.String(parts[0]),
Value: graphql.String(parts[1]),
}), nil
}

return nil
}
func parseEnvVariablesForLocalPreview(cliCtx *cli.Context) ([]EnvironmentVariable, error) {
envVars := make([]EnvironmentVariable, 0)

var err error
for _, ev := range cliCtx.StringSlice(flagOverrideEnvVars.Name) {
if err := parseFn(ev, nil); err != nil {
if envVars, err = parseEnvVar(ev, envVars, nil); err != nil {
return nil, err
}
}

for _, ev := range cliCtx.StringSlice(flagOverrideEnvVarsTF.Name) {
if err := parseFn(ev, func(s string) string {
if envVars, err = parseEnvVar(ev, envVars, func(s string) string {
return strings.Join([]string{"TF_", s}, "")
}); err != nil {
return nil, err
Expand Down

0 comments on commit 5d9039b

Please sign in to comment.