diff --git a/ui/build/config.go b/ui/build/config.go index 925b15385..a451cfe5f 100644 --- a/ui/build/config.go +++ b/ui/build/config.go @@ -176,6 +176,8 @@ func (c *configImpl) parseArgs(ctx Context, args []string) { } else { ctx.Fatalln("Unknown option:", arg) } + } else if k, v, ok := decodeKeyValue(arg); ok && len(k) > 0 { + c.environ.Set(k, v) } else { c.arguments = append(c.arguments, arg) } diff --git a/ui/build/config_test.go b/ui/build/config_test.go index b2a4dd81a..e4eab9442 100644 --- a/ui/build/config_test.go +++ b/ui/build/config_test.go @@ -103,3 +103,72 @@ func TestConfigParseArgsJK(t *testing.T) { }) } } + +func TestConfigParseArgsVars(t *testing.T) { + ctx := testContext() + + testCases := []struct { + env []string + args []string + + expectedEnv []string + remaining []string + }{ + {}, + { + env: []string{"A=bc"}, + + expectedEnv: []string{"A=bc"}, + }, + { + args: []string{"abc"}, + + remaining: []string{"abc"}, + }, + + { + args: []string{"A=bc"}, + + expectedEnv: []string{"A=bc"}, + }, + { + env: []string{"A=a"}, + args: []string{"A=bc"}, + + expectedEnv: []string{"A=bc"}, + }, + + { + env: []string{"A=a"}, + args: []string{"A=", "=b"}, + + expectedEnv: []string{"A="}, + remaining: []string{"=b"}, + }, + } + + for _, tc := range testCases { + t.Run(strings.Join(tc.args, " "), func(t *testing.T) { + defer logger.Recover(func(err error) { + t.Fatal(err) + }) + + e := Environment(tc.env) + c := &configImpl{ + environ: &e, + } + c.parseArgs(ctx, tc.args) + + if !reflect.DeepEqual([]string(*c.environ), tc.expectedEnv) { + t.Errorf("for env=%q args=%q, environment:\nwant: %q\n got: %q\n", + tc.env, tc.args, + tc.expectedEnv, []string(*c.environ)) + } + if !reflect.DeepEqual(c.arguments, tc.remaining) { + t.Errorf("for env=%q args=%q, remaining arguments:\nwant: %q\n got: %q\n", + tc.env, tc.args, + tc.remaining, c.arguments) + } + }) + } +}