mirror of
https://github.com/go-task/task.git
synced 2025-03-17 21:08:01 +02:00
Merge pull request #5 from sascha-andres/master
Simple cyclic dependency detection
This commit is contained in:
commit
f7d119f544
13
README.md
13
README.md
@ -88,6 +88,19 @@ css:
|
||||
- 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
|
||||
|
||||
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 = make(map[string]*Task)
|
||||
|
||||
runTasks = make(map[string]bool)
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -88,6 +90,11 @@ func Run() {
|
||||
|
||||
// RunTask runs a task by its name
|
||||
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]
|
||||
if !ok {
|
||||
return &taskNotFoundError{name}
|
||||
|
Loading…
x
Reference in New Issue
Block a user