mirror of
https://github.com/go-task/task.git
synced 2026-07-02 08:58:41 +00:00
add ignoreError option
This commit is contained in:
@@ -13,13 +13,14 @@ 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
|
||||
Context context.Context
|
||||
Command string
|
||||
Dir string
|
||||
Env []string
|
||||
Stdin io.Reader
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
IgnoreErrorCode bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -62,5 +63,12 @@ func RunCommand(opts *RunCommandOptions) error {
|
||||
if err = r.Reset(); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.Run(p)
|
||||
if err = r.Run(p); err != nil {
|
||||
if opts.IgnoreErrorCode {
|
||||
if _, ok := err.(interp.ExitCode); ok {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package taskfile
|
||||
|
||||
// Call is the parameters to a task call
|
||||
type Call struct {
|
||||
Task string
|
||||
Vars Vars
|
||||
Task string
|
||||
Vars Vars
|
||||
IgnoreError bool
|
||||
}
|
||||
|
||||
@@ -7,16 +7,18 @@ import (
|
||||
|
||||
// Cmd is a task command
|
||||
type Cmd struct {
|
||||
Cmd string
|
||||
Silent bool
|
||||
Task string
|
||||
Vars Vars
|
||||
Cmd string
|
||||
Silent bool
|
||||
Task string
|
||||
Vars Vars
|
||||
IgnoreError bool
|
||||
}
|
||||
|
||||
// Dep is a task dependency
|
||||
type Dep struct {
|
||||
Task string
|
||||
Vars Vars
|
||||
Task string
|
||||
Vars Vars
|
||||
IgnoreError bool
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -38,21 +40,25 @@ func (c *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return nil
|
||||
}
|
||||
var cmdStruct struct {
|
||||
Cmd string
|
||||
Silent bool
|
||||
Cmd string
|
||||
Silent bool
|
||||
IgnoreError bool `yaml:"ignoreError"`
|
||||
}
|
||||
if err := unmarshal(&cmdStruct); err == nil && cmdStruct.Cmd != "" {
|
||||
c.Cmd = cmdStruct.Cmd
|
||||
c.Silent = cmdStruct.Silent
|
||||
c.IgnoreError = cmdStruct.IgnoreError
|
||||
return nil
|
||||
}
|
||||
var taskCall struct {
|
||||
Task string
|
||||
Vars Vars
|
||||
Task string
|
||||
Vars Vars
|
||||
IgnoreError bool `yaml:"ignoreError"`
|
||||
}
|
||||
if err := unmarshal(&taskCall); err == nil {
|
||||
c.Task = taskCall.Task
|
||||
c.Vars = taskCall.Vars
|
||||
c.IgnoreError = taskCall.IgnoreError
|
||||
return nil
|
||||
}
|
||||
return ErrCantUnmarshalCmd
|
||||
@@ -66,12 +72,14 @@ func (d *Dep) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
return nil
|
||||
}
|
||||
var taskCall struct {
|
||||
Task string
|
||||
Vars Vars
|
||||
Task string
|
||||
Vars Vars
|
||||
IgnoreError bool `yaml:"ignoreError"`
|
||||
}
|
||||
if err := unmarshal(&taskCall); err == nil {
|
||||
d.Task = taskCall.Task
|
||||
d.Vars = taskCall.Vars
|
||||
d.IgnoreError = taskCall.IgnoreError
|
||||
return nil
|
||||
}
|
||||
return ErrCantUnmarshalDep
|
||||
|
||||
Reference in New Issue
Block a user