mirror of
https://github.com/go-task/task.git
synced 2025-11-27 22:38:20 +02:00
Merge pull request #5 from sascha-andres/master
Simple cyclic dependency detection
This commit is contained in:
13
README.md
13
README.md
@@ -88,6 +88,19 @@ css:
|
|||||||
- npm run buildcss
|
- npm run buildcss
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Each task can only be run once. If it is included from another dependend task causing
|
||||||
|
a cyclomatic dependency, execution will be stopped.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
task1:
|
||||||
|
deps: [task2]
|
||||||
|
|
||||||
|
task2:
|
||||||
|
deps: [task1]
|
||||||
|
```
|
||||||
|
|
||||||
|
Will stop at the moment the dependencies of `task2` are executed.
|
||||||
|
|
||||||
### Prevent task from running when not necessary
|
### Prevent task from running when not necessary
|
||||||
|
|
||||||
If a task generates something, you can inform Task the source and generated
|
If a task generates something, you can inform Task the source and generated
|
||||||
|
|||||||
7
task.go
7
task.go
@@ -27,6 +27,8 @@ 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)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -88,6 +90,11 @@ 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 {
|
||||||
|
return &taskRunError{taskName: name, err: fmt.Errorf("Cyclic dependency detected")}
|
||||||
|
}
|
||||||
|
runTasks[name] = true
|
||||||
|
|
||||||
t, ok := Tasks[name]
|
t, ok := Tasks[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return &taskNotFoundError{name}
|
return &taskNotFoundError{name}
|
||||||
|
|||||||
Reference in New Issue
Block a user