1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +02:00

Run "set -e" automatically for every command

Without this, multiline command strings won't always exit when they fail.

Closes #403
This commit is contained in:
Andrey Nering
2020-12-27 17:15:12 -03:00
parent 16fad60833
commit ac8e344173
4 changed files with 42 additions and 0 deletions

View File

@@ -27,8 +27,18 @@ type RunCommandOptions struct {
var (
// ErrNilOptions is returned when a nil options is given
ErrNilOptions = errors.New("execext: nil options given")
setMinusE *syntax.File
)
func init() {
var err error
setMinusE, err = syntax.NewParser().Parse(strings.NewReader("set -e"), "")
if err != nil {
panic(err)
}
}
// RunCommand runs a shell command
func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
if opts == nil {
@@ -54,6 +64,9 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
if err != nil {
return err
}
if err = r.Run(ctx, setMinusE); err != nil {
return err
}
return r.Run(ctx, p)
}