From de09e675c1510a1a98eb4e913f2d2c5e3e5443a5 Mon Sep 17 00:00:00 2001 From: Pete Davison Date: Tue, 28 Nov 2023 18:18:28 +0000 Subject: [PATCH] refactor: rename Var.Static to Var.Value --- args/args.go | 6 +++--- args/args_test.go | 28 ++++++++++++++-------------- cmd/task/task.go | 2 +- internal/compiler/env.go | 2 +- internal/compiler/v2/compiler_v2.go | 12 ++++++------ internal/compiler/v3/compiler_v3.go | 16 ++++++++-------- internal/output/output_test.go | 2 +- internal/templater/templater.go | 6 +++--- task_test.go | 2 +- taskfile/read/dotenv.go | 2 +- taskfile/taskfile_test.go | 10 +++++----- taskfile/var.go | 12 ++++++------ variables.go | 8 ++++---- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/args/args.go b/args/args.go index 921b723a..bf01b75e 100644 --- a/args/args.go +++ b/args/args.go @@ -18,7 +18,7 @@ func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) { } name, value := splitVar(arg) - globals.Set(name, taskfile.Var{Static: value}) + globals.Set(name, taskfile.Var{Value: value}) } return calls, globals @@ -37,13 +37,13 @@ func ParseV2(args ...string) ([]taskfile.Call, *taskfile.Vars) { if len(calls) < 1 { name, value := splitVar(arg) - globals.Set(name, taskfile.Var{Static: value}) + globals.Set(name, taskfile.Var{Value: value}) } else { if calls[len(calls)-1].Vars == nil { calls[len(calls)-1].Vars = &taskfile.Vars{} } name, value := splitVar(arg) - calls[len(calls)-1].Vars.Set(name, taskfile.Var{Static: value}) + calls[len(calls)-1].Vars.Set(name, taskfile.Var{Value: value}) } } diff --git a/args/args_test.go b/args/args_test.go index 5cea4b02..042e9a9d 100644 --- a/args/args_test.go +++ b/args/args_test.go @@ -35,9 +35,9 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, - "BAR": {Static: "baz"}, - "BAZ": {Static: "foo"}, + "FOO": {Value: "bar"}, + "BAR": {Value: "baz"}, + "BAZ": {Value: "foo"}, }, []string{"FOO", "BAR", "BAZ"}, ), @@ -51,7 +51,7 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "CONTENT": {Static: "with some spaces"}, + "CONTENT": {Value: "with some spaces"}, }, []string{"CONTENT"}, ), @@ -66,7 +66,7 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, + "FOO": {Value: "bar"}, }, []string{"FOO"}, ), @@ -86,8 +86,8 @@ func TestArgsV3(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, - "BAR": {Static: "baz"}, + "FOO": {Value: "bar"}, + "BAR": {Value: "baz"}, }, []string{"FOO", "BAR"}, ), @@ -130,7 +130,7 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, + "FOO": {Value: "bar"}, }, []string{"FOO"}, ), @@ -143,8 +143,8 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "BAR": {Static: "baz"}, - "BAZ": {Static: "foo"}, + "BAR": {Value: "baz"}, + "BAZ": {Value: "foo"}, }, []string{"BAR", "BAZ"}, ), @@ -161,7 +161,7 @@ func TestArgsV2(t *testing.T) { Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "CONTENT": {Static: "with some spaces"}, + "CONTENT": {Value: "with some spaces"}, }, []string{"CONTENT"}, ), @@ -178,7 +178,7 @@ func TestArgsV2(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, + "FOO": {Value: "bar"}, }, []string{"FOO"}, ), @@ -198,8 +198,8 @@ func TestArgsV2(t *testing.T) { ExpectedGlobals: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "FOO": {Static: "bar"}, - "BAR": {Static: "baz"}, + "FOO": {Value: "bar"}, + "BAR": {Value: "baz"}, }, []string{"FOO", "BAR"}, ), diff --git a/cmd/task/task.go b/cmd/task/task.go index b0edda29..939245db 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -311,7 +311,7 @@ func run() error { calls = append(calls, taskfile.Call{Task: "default", Direct: true}) } - globals.Set("CLI_ARGS", taskfile.Var{Static: cliArgs}) + globals.Set("CLI_ARGS", taskfile.Var{Value: cliArgs}) e.Taskfile.Vars.Merge(globals) if !flags.watch { diff --git a/internal/compiler/env.go b/internal/compiler/env.go index b68e8ac1..751b1ea1 100644 --- a/internal/compiler/env.go +++ b/internal/compiler/env.go @@ -14,7 +14,7 @@ func GetEnviron() *taskfile.Vars { for _, e := range os.Environ() { keyVal := strings.SplitN(e, "=", 2) key, val := keyVal[0], keyVal[1] - m.Set(key, taskfile.Var{Static: val}) + m.Set(key, taskfile.Var{Value: val}) } return m } diff --git a/internal/compiler/v2/compiler_v2.go b/internal/compiler/v2/compiler_v2.go index e849d044..97610a7f 100644 --- a/internal/compiler/v2/compiler_v2.go +++ b/internal/compiler/v2/compiler_v2.go @@ -50,7 +50,7 @@ func (c *CompilerV2) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi c: c, vars: compiler.GetEnviron(), } - vr.vars.Set("TASK", taskfile.Var{Static: t.Task}) + vr.vars.Set("TASK", taskfile.Var{Value: t.Task}) for _, vars := range []*taskfile.Vars{c.Taskvars, c.TaskfileVars, call.Vars, t.Vars} { for i := 0; i < c.Expansions; i++ { @@ -73,23 +73,23 @@ func (vr *varResolver) merge(vars *taskfile.Vars) { tr := templater.Templater{Vars: vr.vars} _ = vars.Range(func(k string, v taskfile.Var) error { v = taskfile.Var{ - Static: tr.Replace(v.Static), - Sh: tr.Replace(v.Sh), + Value: tr.Replace(v.Value), + Sh: tr.Replace(v.Sh), } static, err := vr.c.HandleDynamicVar(v, "") if err != nil { vr.err = err return err } - vr.vars.Set(k, taskfile.Var{Static: static}) + vr.vars.Set(k, taskfile.Var{Value: static}) return nil }) vr.err = tr.Err() } func (c *CompilerV2) HandleDynamicVar(v taskfile.Var, _ string) (string, error) { - if v.Static != "" || v.Sh == "" { - return v.Static, nil + if v.Value != "" || v.Sh == "" { + return v.Value, nil } c.muDynamicCache.Lock() diff --git a/internal/compiler/v3/compiler_v3.go b/internal/compiler/v3/compiler_v3.go index a5c6a48a..bc5a86d1 100644 --- a/internal/compiler/v3/compiler_v3.go +++ b/internal/compiler/v3/compiler_v3.go @@ -51,7 +51,7 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat return nil, err } for k, v := range specialVars { - result.Set(k, taskfile.Var{Static: v}) + result.Set(k, taskfile.Var{Value: v}) } } @@ -60,14 +60,14 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat tr := templater.Templater{Vars: result, RemoveNoValue: true} if !evaluateShVars { - result.Set(k, taskfile.Var{Static: tr.Replace(v.Static)}) + result.Set(k, taskfile.Var{Value: tr.Replace(v.Value)}) return nil } v = taskfile.Var{ - Static: tr.Replace(v.Static), - Sh: tr.Replace(v.Sh), - Dir: v.Dir, + Value: tr.Replace(v.Value), + Sh: tr.Replace(v.Sh), + Dir: v.Dir, } if err := tr.Err(); err != nil { return err @@ -76,7 +76,7 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat if err != nil { return err } - result.Set(k, taskfile.Var{Static: static}) + result.Set(k, taskfile.Var{Value: static}) return nil } } @@ -125,8 +125,8 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat } func (c *CompilerV3) HandleDynamicVar(v taskfile.Var, dir string) (string, error) { - if v.Static != "" || v.Sh == "" { - return v.Static, nil + if v.Value != "" || v.Sh == "" { + return v.Value, nil } c.muDynamicCache.Lock() diff --git a/internal/output/output_test.go b/internal/output/output_test.go index 5d099381..bc55f730 100644 --- a/internal/output/output_test.go +++ b/internal/output/output_test.go @@ -49,7 +49,7 @@ func TestGroupWithBeginEnd(t *testing.T) { tmpl := templater.Templater{ Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMap(map[string]taskfile.Var{ - "VAR1": {Static: "example-value"}, + "VAR1": {Value: "example-value"}, }), }, } diff --git a/internal/templater/templater.go b/internal/templater/templater.go index 2b8213b3..5094c66e 100644 --- a/internal/templater/templater.go +++ b/internal/templater/templater.go @@ -111,9 +111,9 @@ func (r *Templater) replaceVars(vars *taskfile.Vars, extra map[string]any) *task var new taskfile.Vars _ = vars.Range(func(k string, v taskfile.Var) error { new.Set(k, taskfile.Var{ - Static: r.ReplaceWithExtra(v.Static, extra), - Live: v.Live, - Sh: r.ReplaceWithExtra(v.Sh, extra), + Value: r.ReplaceWithExtra(v.Value, extra), + Live: v.Live, + Sh: r.ReplaceWithExtra(v.Sh, extra), }) return nil }) diff --git a/task_test.go b/task_test.go index 66b89171..d6e63bb4 100644 --- a/task_test.go +++ b/task_test.go @@ -2111,7 +2111,7 @@ func TestSplitArgs(t *testing.T) { require.NoError(t, e.Setup()) vars := &taskfile.Vars{} - vars.Set("CLI_ARGS", taskfile.Var{Static: "foo bar 'foo bar baz'"}) + vars.Set("CLI_ARGS", taskfile.Var{Value: "foo bar 'foo bar baz'"}) err := e.Run(context.Background(), taskfile.Call{Task: "default", Vars: vars}) require.NoError(t, err) diff --git a/taskfile/read/dotenv.go b/taskfile/read/dotenv.go index 8aa4da65..9828e6d4 100644 --- a/taskfile/read/dotenv.go +++ b/taskfile/read/dotenv.go @@ -42,7 +42,7 @@ func Dotenv(c compiler.Compiler, tf *taskfile.Taskfile, dir string) (*taskfile.V } for key, value := range envs { if ok := env.Exists(key); !ok { - env.Set(key, taskfile.Var{Static: value}) + env.Set(key, taskfile.Var{Value: value}) } } } diff --git a/taskfile/taskfile_test.go b/taskfile/taskfile_test.go index 17542ecc..e43115a6 100644 --- a/taskfile/taskfile_test.go +++ b/taskfile/taskfile_test.go @@ -41,8 +41,8 @@ vars: Task: "another-task", Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "PARAM1": {Static: "VALUE1"}, - "PARAM2": {Static: "VALUE2"}, + "PARAM1": {Value: "VALUE1"}, + "PARAM2": {Value: "VALUE2"}, }, []string{"PARAM1", "PARAM2"}, ), @@ -61,7 +61,7 @@ vars: Task: "some_task", Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "PARAM1": {Static: "var"}, + "PARAM1": {Value: "var"}, }, []string{"PARAM1"}, ), @@ -81,8 +81,8 @@ vars: Task: "another-task", Vars: &taskfile.Vars{ OrderedMap: orderedmap.FromMapWithOrder( map[string]taskfile.Var{ - "PARAM1": {Static: "VALUE1"}, - "PARAM2": {Static: "VALUE2"}, + "PARAM1": {Value: "VALUE1"}, + "PARAM2": {Value: "VALUE2"}, }, []string{"PARAM1", "PARAM2"}, ), diff --git a/taskfile/var.go b/taskfile/var.go index ba1c2d26..f601604f 100644 --- a/taskfile/var.go +++ b/taskfile/var.go @@ -27,7 +27,7 @@ func (vs *Vars) ToCacheMap() (m map[string]any) { if v.Live != nil { m[k] = v.Live } else { - m[k] = v.Static + m[k] = v.Value } return nil }) @@ -71,10 +71,10 @@ func (vs *Vars) DeepCopy() *Vars { // Var represents either a static or dynamic variable. type Var struct { - Static string - Live any - Sh string - Dir string + Value string + Live any + Sh string + Dir string } func (v *Var) UnmarshalYAML(node *yaml.Node) error { @@ -85,7 +85,7 @@ func (v *Var) UnmarshalYAML(node *yaml.Node) error { if err := node.Decode(&str); err != nil { return err } - v.Static = str + v.Value = str return nil case yaml.MappingNode: diff --git a/variables.go b/variables.go index 3237652f..e1c7a737 100644 --- a/variables.go +++ b/variables.go @@ -96,7 +96,7 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf } for key, value := range envs { if ok := dotenvEnvs.Exists(key); !ok { - dotenvEnvs.Set(key, taskfile.Var{Static: value}) + dotenvEnvs.Set(key, taskfile.Var{Value: value}) } } } @@ -112,7 +112,7 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf if err != nil { return err } - new.Env.Set(k, taskfile.Var{Static: static}) + new.Env.Set(k, taskfile.Var{Value: static}) return nil }) if err != nil { @@ -150,9 +150,9 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf if vars != nil { v := vars.Get(cmd.For.Var) if cmd.For.Split != "" { - list = strings.Split(v.Static, cmd.For.Split) + list = strings.Split(v.Value, cmd.For.Split) } else { - list = strings.Fields(v.Static) + list = strings.Fields(v.Value) } } }