mirror of
https://github.com/go-task/task.git
synced 2025-06-06 23:46:46 +02:00
Handle ignore_error one level up on the code
This commit is contained in:
parent
550c116aea
commit
c70343a5bc
@ -20,7 +20,6 @@ type RunCommandOptions struct {
|
|||||||
Stdin io.Reader
|
Stdin io.Reader
|
||||||
Stdout io.Writer
|
Stdout io.Writer
|
||||||
Stderr io.Writer
|
Stderr io.Writer
|
||||||
IgnoreErrorCode bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -63,12 +62,5 @@ func RunCommand(opts *RunCommandOptions) error {
|
|||||||
if err = r.Reset(); err != nil {
|
if err = r.Reset(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = r.Run(p); err != nil {
|
return r.Run(p)
|
||||||
if opts.IgnoreErrorCode {
|
|
||||||
if _, ok := err.(interp.ExitCode); ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
9
task.go
9
task.go
@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/Masterminds/semver"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
"mvdan.cc/sh/interp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -221,7 +222,7 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
|||||||
defer stdOut.Close()
|
defer stdOut.Close()
|
||||||
defer stdErr.Close()
|
defer stdErr.Close()
|
||||||
|
|
||||||
return execext.RunCommand(&execext.RunCommandOptions{
|
err := execext.RunCommand(&execext.RunCommandOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
Command: cmd.Cmd,
|
Command: cmd.Cmd,
|
||||||
Dir: t.Dir,
|
Dir: t.Dir,
|
||||||
@ -229,8 +230,12 @@ func (e *Executor) runCommand(ctx context.Context, t *taskfile.Task, call taskfi
|
|||||||
Stdin: e.Stdin,
|
Stdin: e.Stdin,
|
||||||
Stdout: stdOut,
|
Stdout: stdOut,
|
||||||
Stderr: stdErr,
|
Stderr: stdErr,
|
||||||
IgnoreErrorCode: cmd.IgnoreError,
|
|
||||||
})
|
})
|
||||||
|
if _, ok := err.(interp.ExitCode); ok && cmd.IgnoreError {
|
||||||
|
e.Logger.VerboseErrf("task: command error ignored: %v", err)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user