mirror of
https://github.com/go-task/task.git
synced 2024-12-04 10:24:45 +02:00
refactor: rename Var.Static to Var.Value
This commit is contained in:
parent
f58257a208
commit
de09e675c1
@ -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})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"},
|
||||
),
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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"},
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
|
@ -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)
|
||||
|
@ -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})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"},
|
||||
),
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user