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