1
0
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:
Andrey Nering 2018-08-05 12:40:11 -03:00
parent 550c116aea
commit c70343a5bc
2 changed files with 22 additions and 25 deletions

View File

@ -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
View File

@ -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
}