1
0
mirror of https://github.com/go-task/task.git synced 2025-08-10 22:42:19 +02:00

Minor improvements for #5

This commit is contained in:
Andrey Nering
2017-03-02 20:45:52 -03:00
parent f7d119f544
commit b8116015c7

16
task.go
View File

@@ -28,7 +28,7 @@ var (
// Tasks constains the tasks parsed from Taskfile // Tasks constains the tasks parsed from Taskfile
Tasks = make(map[string]*Task) Tasks = make(map[string]*Task)
runTasks = make(map[string]bool) runnedTasks = make(map[string]struct{})
) )
func init() { func init() {
@@ -66,6 +66,14 @@ func (err *taskRunError) Error() string {
return fmt.Sprintf(`Failed to run task "%s": %v`, err.taskName, err.err) return fmt.Sprintf(`Failed to run task "%s": %v`, err.taskName, err.err)
} }
type cyclicDepError struct {
taskName string
}
func (err *cyclicDepError) Error() string {
return fmt.Sprintf(`Cyclic dependency of task "%s" detected`, err.taskName)
}
// Run runs Task // Run runs Task
func Run() { func Run() {
log.SetFlags(0) log.SetFlags(0)
@@ -90,10 +98,10 @@ func Run() {
// RunTask runs a task by its name // RunTask runs a task by its name
func RunTask(name string) error { func RunTask(name string) error {
if _, found := runTasks[name]; found { if _, found := runnedTasks[name]; found {
return &taskRunError{taskName: name, err: fmt.Errorf("Cyclic dependency detected")} return &cyclicDepError{name}
} }
runTasks[name] = true runnedTasks[name] = struct{}{}
t, ok := Tasks[name] t, ok := Tasks[name]
if !ok { if !ok {