Remove ignore_errors

This commit is contained in:
Stephen Prater
2019-05-28 13:02:59 -07:00
parent 659cae6a4c
commit 044d3a0ff9
7 changed files with 39 additions and 95 deletions

View File

@@ -12,9 +12,8 @@ var (
// Precondition represents a precondition necessary for a task to run
type Precondition struct {
Sh string
Msg string
IgnoreError bool
Sh string
Msg string
}
// UnmarshalYAML implements yaml.Unmarshaler interface.
@@ -24,28 +23,23 @@ func (p *Precondition) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&cmd); err == nil {
p.Sh = cmd
p.Msg = fmt.Sprintf("`%s` failed", cmd)
p.IgnoreError = false
return nil
}
var sh struct {
Sh string
Msg string
IgnoreError bool `yaml:"ignore_error"`
Sh string
Msg string
}
err := unmarshal(&sh)
if err == nil {
p.Sh = sh.Sh
p.Msg = sh.Msg
if p.Msg == "" {
p.Msg = fmt.Sprintf("%s failed", sh.Sh)
}
p.IgnoreError = sh.IgnoreError
return nil
if err := unmarshal(&sh); err != nil {
return err
}
return err
p.Sh = sh.Sh
p.Msg = sh.Msg
if p.Msg == "" {
p.Msg = fmt.Sprintf("%s failed", sh.Sh)
}
return nil
}

View File

@@ -18,27 +18,26 @@ func TestPreconditionParse(t *testing.T) {
{
"test -f foo.txt",
&taskfile.Precondition{},
&taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed", IgnoreError: false},
&taskfile.Precondition{Sh: `test -f foo.txt`, Msg: "`test -f foo.txt` failed"},
},
{
"sh: '[ 1 = 0 ]'",
&taskfile.Precondition{},
&taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed", IgnoreError: false},
&taskfile.Precondition{Sh: "[ 1 = 0 ]", Msg: "[ 1 = 0 ] failed"},
},
{`
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
`,
&taskfile.Precondition{},
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2", IgnoreError: false},
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
},
{`
sh: "[ 1 = 2 ]"
msg: "1 is not 2"
ignore_error: true
`,
&taskfile.Precondition{},
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2", IgnoreError: true},
&taskfile.Precondition{Sh: "[ 1 = 2 ]", Msg: "1 is not 2"},
},
}
for _, test := range tests {