1
0
mirror of https://github.com/go-task/task.git synced 2025-01-04 03:48:02 +02:00

feat: invert call.Direct (#1459)

This commit is contained in:
Pete Davison 2024-01-11 00:32:49 +00:00 committed by GitHub
parent 07e6f5cad7
commit 42af0fc791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 22 deletions

View File

@ -13,7 +13,7 @@ func Parse(args ...string) ([]ast.Call, *ast.Vars) {
for _, arg := range args {
if !strings.Contains(arg, "=") {
calls = append(calls, ast.Call{Task: arg, Direct: true})
calls = append(calls, ast.Call{Task: arg})
continue
}

View File

@ -20,17 +20,17 @@ func TestArgs(t *testing.T) {
{
Args: []string{"task-a", "task-b", "task-c"},
ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true},
{Task: "task-b", Direct: true},
{Task: "task-c", Direct: true},
{Task: "task-a"},
{Task: "task-b"},
{Task: "task-c"},
},
},
{
Args: []string{"task-a", "FOO=bar", "task-b", "task-c", "BAR=baz", "BAZ=foo"},
ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true},
{Task: "task-b", Direct: true},
{Task: "task-c", Direct: true},
{Task: "task-a"},
{Task: "task-b"},
{Task: "task-c"},
},
ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
@ -46,7 +46,7 @@ func TestArgs(t *testing.T) {
{
Args: []string{"task-a", "CONTENT=with some spaces"},
ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true},
{Task: "task-a"},
},
ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder(
@ -60,8 +60,8 @@ func TestArgs(t *testing.T) {
{
Args: []string{"FOO=bar", "task-a", "task-b"},
ExpectedCalls: []ast.Call{
{Task: "task-a", Direct: true},
{Task: "task-b", Direct: true},
{Task: "task-a"},
{Task: "task-b"},
},
ExpectedGlobals: &ast.Vars{
OrderedMap: orderedmap.FromMapWithOrder(

View File

@ -304,7 +304,7 @@ func run() error {
// If there are no calls, run the default task instead
if len(calls) == 0 {
calls = append(calls, ast.Call{Task: "default", Direct: true})
calls = append(calls, ast.Call{Task: "default"})
}
globals.Set("CLI_ARGS", ast.Var{Value: cliArgs})

View File

@ -199,7 +199,7 @@ func (e *Executor) RunTask(ctx context.Context, call ast.Call) error {
return err
}
skipFingerprinting := e.ForceAll || (call.Direct && e.Force)
skipFingerprinting := e.ForceAll || (!call.Indirect && e.Force)
if !skipFingerprinting {
if err := ctx.Err(); err != nil {
return err
@ -258,7 +258,7 @@ func (e *Executor) RunTask(ctx context.Context, call ast.Call) error {
continue
}
if !call.Direct {
if call.Indirect {
return err
}
@ -296,7 +296,7 @@ func (e *Executor) runDeps(ctx context.Context, t *ast.Task) error {
for _, d := range t.Deps {
d := d
g.Go(func() error {
err := e.RunTask(ctx, ast.Call{Task: d.Task, Vars: d.Vars, Silent: d.Silent})
err := e.RunTask(ctx, ast.Call{Task: d.Task, Vars: d.Vars, Silent: d.Silent, Indirect: true})
if err != nil {
return err
}
@ -324,7 +324,7 @@ func (e *Executor) runCommand(ctx context.Context, t *ast.Task, call ast.Call, i
reacquire := e.releaseConcurrencyLimit()
defer reacquire()
err := e.RunTask(ctx, ast.Call{Task: cmd.Task, Vars: cmd.Vars, Silent: cmd.Silent})
err := e.RunTask(ctx, ast.Call{Task: cmd.Task, Vars: cmd.Vars, Silent: cmd.Silent, Indirect: true})
if err != nil {
return err
}

View File

@ -1789,7 +1789,7 @@ func TestErrorCode(t *testing.T) {
}
require.NoError(t, e.Setup())
err := e.Run(context.Background(), ast.Call{Task: test.task, Direct: true})
err := e.Run(context.Background(), ast.Call{Task: test.task})
require.Error(t, err)
taskRunErr, ok := err.(*errors.TaskRunError)
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
@ -2183,7 +2183,7 @@ func TestForce(t *testing.T) {
ForceAll: tt.forceAll,
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), ast.Call{Task: "task-with-dep", Direct: true}))
require.NoError(t, e.Run(context.Background(), ast.Call{Task: "task-with-dep"}))
})
}
}
@ -2238,7 +2238,7 @@ func TestFor(t *testing.T) {
Force: true,
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), ast.Call{Task: test.name, Direct: true}))
require.NoError(t, e.Run(context.Background(), ast.Call{Task: test.name}))
assert.Equal(t, test.expectedOutput, buff.String())
})
}

View File

@ -2,8 +2,8 @@ package ast
// Call is the parameters to a task call
type Call struct {
Task string
Vars *Vars
Silent bool
Direct bool // Was the task called directly or via another task?
Task string
Vars *Vars
Silent bool
Indirect bool // True if the task was called by another task
}