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:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user