1
0
mirror of https://github.com/go-task/task.git synced 2024-12-12 10:45:49 +02:00
task/command.go
2017-07-03 21:04:38 -03:00

65 lines
1.1 KiB
Go

package task
import (
"errors"
"strings"
)
type Params map[string]string
type Cmd struct {
Cmd string
Task string
Params Params
}
type Dep struct {
Task string
Params Params
}
var (
ErrCantUnmarshalCmd = errors.New("task: can't unmarshal cmd value")
ErrCantUnmarshalDep = errors.New("task: can't unmarshal dep value")
)
func (c *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) error {
var cmd string
if err := unmarshal(&cmd); err == nil {
if strings.HasPrefix(cmd, "^") {
c.Task = strings.TrimPrefix(cmd, "^")
} else {
c.Cmd = cmd
}
return nil
}
var taskCall struct {
Task string
Params Params
}
if err := unmarshal(&taskCall); err == nil {
c.Task = taskCall.Task
c.Params = taskCall.Params
return nil
}
return ErrCantUnmarshalCmd
}
func (d *Dep) UnmarshalYAML(unmarshal func(interface{}) error) error {
var task string
if err := unmarshal(&task); err == nil {
d.Task = task
return nil
}
var taskCall struct {
Task string
Params Params
}
if err := unmarshal(&taskCall); err == nil {
d.Task = taskCall.Task
d.Params = taskCall.Params
return nil
}
return ErrCantUnmarshalDep
}