1
0
mirror of https://github.com/go-task/task.git synced 2025-08-08 22:36:57 +02:00

refactor: rename Var.Static to Var.Value

This commit is contained in:
Pete Davison
2023-11-28 18:18:28 +00:00
parent f58257a208
commit de09e675c1
13 changed files with 54 additions and 54 deletions

View File

@ -18,7 +18,7 @@ func ParseV3(args ...string) ([]taskfile.Call, *taskfile.Vars) {
} }
name, value := splitVar(arg) name, value := splitVar(arg)
globals.Set(name, taskfile.Var{Static: value}) globals.Set(name, taskfile.Var{Value: value})
} }
return calls, globals return calls, globals
@ -37,13 +37,13 @@ func ParseV2(args ...string) ([]taskfile.Call, *taskfile.Vars) {
if len(calls) < 1 { if len(calls) < 1 {
name, value := splitVar(arg) name, value := splitVar(arg)
globals.Set(name, taskfile.Var{Static: value}) globals.Set(name, taskfile.Var{Value: value})
} else { } else {
if calls[len(calls)-1].Vars == nil { if calls[len(calls)-1].Vars == nil {
calls[len(calls)-1].Vars = &taskfile.Vars{} calls[len(calls)-1].Vars = &taskfile.Vars{}
} }
name, value := splitVar(arg) 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})
} }
} }

View File

@ -35,9 +35,9 @@ func TestArgsV3(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
"BAR": {Static: "baz"}, "BAR": {Value: "baz"},
"BAZ": {Static: "foo"}, "BAZ": {Value: "foo"},
}, },
[]string{"FOO", "BAR", "BAZ"}, []string{"FOO", "BAR", "BAZ"},
), ),
@ -51,7 +51,7 @@ func TestArgsV3(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"CONTENT": {Static: "with some spaces"}, "CONTENT": {Value: "with some spaces"},
}, },
[]string{"CONTENT"}, []string{"CONTENT"},
), ),
@ -66,7 +66,7 @@ func TestArgsV3(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
}, },
[]string{"FOO"}, []string{"FOO"},
), ),
@ -86,8 +86,8 @@ func TestArgsV3(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
"BAR": {Static: "baz"}, "BAR": {Value: "baz"},
}, },
[]string{"FOO", "BAR"}, []string{"FOO", "BAR"},
), ),
@ -130,7 +130,7 @@ func TestArgsV2(t *testing.T) {
Vars: &taskfile.Vars{ Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
}, },
[]string{"FOO"}, []string{"FOO"},
), ),
@ -143,8 +143,8 @@ func TestArgsV2(t *testing.T) {
Vars: &taskfile.Vars{ Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"BAR": {Static: "baz"}, "BAR": {Value: "baz"},
"BAZ": {Static: "foo"}, "BAZ": {Value: "foo"},
}, },
[]string{"BAR", "BAZ"}, []string{"BAR", "BAZ"},
), ),
@ -161,7 +161,7 @@ func TestArgsV2(t *testing.T) {
Vars: &taskfile.Vars{ Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"CONTENT": {Static: "with some spaces"}, "CONTENT": {Value: "with some spaces"},
}, },
[]string{"CONTENT"}, []string{"CONTENT"},
), ),
@ -178,7 +178,7 @@ func TestArgsV2(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
}, },
[]string{"FOO"}, []string{"FOO"},
), ),
@ -198,8 +198,8 @@ func TestArgsV2(t *testing.T) {
ExpectedGlobals: &taskfile.Vars{ ExpectedGlobals: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"FOO": {Static: "bar"}, "FOO": {Value: "bar"},
"BAR": {Static: "baz"}, "BAR": {Value: "baz"},
}, },
[]string{"FOO", "BAR"}, []string{"FOO", "BAR"},
), ),

View File

@ -311,7 +311,7 @@ func run() error {
calls = append(calls, taskfile.Call{Task: "default", Direct: true}) 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) e.Taskfile.Vars.Merge(globals)
if !flags.watch { if !flags.watch {

View File

@ -14,7 +14,7 @@ func GetEnviron() *taskfile.Vars {
for _, e := range os.Environ() { for _, e := range os.Environ() {
keyVal := strings.SplitN(e, "=", 2) keyVal := strings.SplitN(e, "=", 2)
key, val := keyVal[0], keyVal[1] key, val := keyVal[0], keyVal[1]
m.Set(key, taskfile.Var{Static: val}) m.Set(key, taskfile.Var{Value: val})
} }
return m return m
} }

View File

@ -50,7 +50,7 @@ func (c *CompilerV2) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
c: c, c: c,
vars: compiler.GetEnviron(), 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 _, vars := range []*taskfile.Vars{c.Taskvars, c.TaskfileVars, call.Vars, t.Vars} {
for i := 0; i < c.Expansions; i++ { for i := 0; i < c.Expansions; i++ {
@ -73,23 +73,23 @@ func (vr *varResolver) merge(vars *taskfile.Vars) {
tr := templater.Templater{Vars: vr.vars} tr := templater.Templater{Vars: vr.vars}
_ = vars.Range(func(k string, v taskfile.Var) error { _ = vars.Range(func(k string, v taskfile.Var) error {
v = taskfile.Var{ v = taskfile.Var{
Static: tr.Replace(v.Static), Value: tr.Replace(v.Value),
Sh: tr.Replace(v.Sh), Sh: tr.Replace(v.Sh),
} }
static, err := vr.c.HandleDynamicVar(v, "") static, err := vr.c.HandleDynamicVar(v, "")
if err != nil { if err != nil {
vr.err = err vr.err = err
return err return err
} }
vr.vars.Set(k, taskfile.Var{Static: static}) vr.vars.Set(k, taskfile.Var{Value: static})
return nil return nil
}) })
vr.err = tr.Err() vr.err = tr.Err()
} }
func (c *CompilerV2) HandleDynamicVar(v taskfile.Var, _ string) (string, error) { func (c *CompilerV2) HandleDynamicVar(v taskfile.Var, _ string) (string, error) {
if v.Static != "" || v.Sh == "" { if v.Value != "" || v.Sh == "" {
return v.Static, nil return v.Value, nil
} }
c.muDynamicCache.Lock() c.muDynamicCache.Lock()

View File

@ -51,7 +51,7 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat
return nil, err return nil, err
} }
for k, v := range specialVars { 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} tr := templater.Templater{Vars: result, RemoveNoValue: true}
if !evaluateShVars { if !evaluateShVars {
result.Set(k, taskfile.Var{Static: tr.Replace(v.Static)}) result.Set(k, taskfile.Var{Value: tr.Replace(v.Value)})
return nil return nil
} }
v = taskfile.Var{ v = taskfile.Var{
Static: tr.Replace(v.Static), Value: tr.Replace(v.Value),
Sh: tr.Replace(v.Sh), Sh: tr.Replace(v.Sh),
Dir: v.Dir, Dir: v.Dir,
} }
if err := tr.Err(); err != nil { if err := tr.Err(); err != nil {
return err return err
@ -76,7 +76,7 @@ func (c *CompilerV3) getVariables(t *taskfile.Task, call *taskfile.Call, evaluat
if err != nil { if err != nil {
return err return err
} }
result.Set(k, taskfile.Var{Static: static}) result.Set(k, taskfile.Var{Value: static})
return nil 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) { func (c *CompilerV3) HandleDynamicVar(v taskfile.Var, dir string) (string, error) {
if v.Static != "" || v.Sh == "" { if v.Value != "" || v.Sh == "" {
return v.Static, nil return v.Value, nil
} }
c.muDynamicCache.Lock() c.muDynamicCache.Lock()

View File

@ -49,7 +49,7 @@ func TestGroupWithBeginEnd(t *testing.T) {
tmpl := templater.Templater{ tmpl := templater.Templater{
Vars: &taskfile.Vars{ Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMap(map[string]taskfile.Var{ OrderedMap: orderedmap.FromMap(map[string]taskfile.Var{
"VAR1": {Static: "example-value"}, "VAR1": {Value: "example-value"},
}), }),
}, },
} }

View File

@ -111,9 +111,9 @@ func (r *Templater) replaceVars(vars *taskfile.Vars, extra map[string]any) *task
var new taskfile.Vars var new taskfile.Vars
_ = vars.Range(func(k string, v taskfile.Var) error { _ = vars.Range(func(k string, v taskfile.Var) error {
new.Set(k, taskfile.Var{ new.Set(k, taskfile.Var{
Static: r.ReplaceWithExtra(v.Static, extra), Value: r.ReplaceWithExtra(v.Value, extra),
Live: v.Live, Live: v.Live,
Sh: r.ReplaceWithExtra(v.Sh, extra), Sh: r.ReplaceWithExtra(v.Sh, extra),
}) })
return nil return nil
}) })

View File

@ -2111,7 +2111,7 @@ func TestSplitArgs(t *testing.T) {
require.NoError(t, e.Setup()) require.NoError(t, e.Setup())
vars := &taskfile.Vars{} 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}) err := e.Run(context.Background(), taskfile.Call{Task: "default", Vars: vars})
require.NoError(t, err) require.NoError(t, err)

View File

@ -42,7 +42,7 @@ func Dotenv(c compiler.Compiler, tf *taskfile.Taskfile, dir string) (*taskfile.V
} }
for key, value := range envs { for key, value := range envs {
if ok := env.Exists(key); !ok { if ok := env.Exists(key); !ok {
env.Set(key, taskfile.Var{Static: value}) env.Set(key, taskfile.Var{Value: value})
} }
} }
} }

View File

@ -41,8 +41,8 @@ vars:
Task: "another-task", Vars: &taskfile.Vars{ Task: "another-task", Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"PARAM1": {Static: "VALUE1"}, "PARAM1": {Value: "VALUE1"},
"PARAM2": {Static: "VALUE2"}, "PARAM2": {Value: "VALUE2"},
}, },
[]string{"PARAM1", "PARAM2"}, []string{"PARAM1", "PARAM2"},
), ),
@ -61,7 +61,7 @@ vars:
Task: "some_task", Vars: &taskfile.Vars{ Task: "some_task", Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"PARAM1": {Static: "var"}, "PARAM1": {Value: "var"},
}, },
[]string{"PARAM1"}, []string{"PARAM1"},
), ),
@ -81,8 +81,8 @@ vars:
Task: "another-task", Vars: &taskfile.Vars{ Task: "another-task", Vars: &taskfile.Vars{
OrderedMap: orderedmap.FromMapWithOrder( OrderedMap: orderedmap.FromMapWithOrder(
map[string]taskfile.Var{ map[string]taskfile.Var{
"PARAM1": {Static: "VALUE1"}, "PARAM1": {Value: "VALUE1"},
"PARAM2": {Static: "VALUE2"}, "PARAM2": {Value: "VALUE2"},
}, },
[]string{"PARAM1", "PARAM2"}, []string{"PARAM1", "PARAM2"},
), ),

View File

@ -27,7 +27,7 @@ func (vs *Vars) ToCacheMap() (m map[string]any) {
if v.Live != nil { if v.Live != nil {
m[k] = v.Live m[k] = v.Live
} else { } else {
m[k] = v.Static m[k] = v.Value
} }
return nil return nil
}) })
@ -71,10 +71,10 @@ func (vs *Vars) DeepCopy() *Vars {
// Var represents either a static or dynamic variable. // Var represents either a static or dynamic variable.
type Var struct { type Var struct {
Static string Value string
Live any Live any
Sh string Sh string
Dir string Dir string
} }
func (v *Var) UnmarshalYAML(node *yaml.Node) error { 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 { if err := node.Decode(&str); err != nil {
return err return err
} }
v.Static = str v.Value = str
return nil return nil
case yaml.MappingNode: case yaml.MappingNode:

View File

@ -96,7 +96,7 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf
} }
for key, value := range envs { for key, value := range envs {
if ok := dotenvEnvs.Exists(key); !ok { 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 { if err != nil {
return err return err
} }
new.Env.Set(k, taskfile.Var{Static: static}) new.Env.Set(k, taskfile.Var{Value: static})
return nil return nil
}) })
if err != nil { if err != nil {
@ -150,9 +150,9 @@ func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskf
if vars != nil { if vars != nil {
v := vars.Get(cmd.For.Var) v := vars.Get(cmd.For.Var)
if cmd.For.Split != "" { if cmd.For.Split != "" {
list = strings.Split(v.Static, cmd.For.Split) list = strings.Split(v.Value, cmd.For.Split)
} else { } else {
list = strings.Fields(v.Static) list = strings.Fields(v.Value)
} }
} }
} }