mirror of
https://github.com/go-task/task.git
synced 2025-04-23 12:18:57 +02:00
42 lines
706 B
Go
42 lines
706 B
Go
package ast
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/dominikbraun/graph"
|
|
"github.com/dominikbraun/graph/draw"
|
|
)
|
|
|
|
type TaskfileGraph struct {
|
|
graph.Graph[string, *TaskfileVertex]
|
|
}
|
|
|
|
// A TaskfileVertex is a vertex on the Taskfile DAG.
|
|
type TaskfileVertex struct {
|
|
URI string
|
|
Taskfile *Taskfile
|
|
}
|
|
|
|
func taskfileHash(vertex *TaskfileVertex) string {
|
|
return vertex.URI
|
|
}
|
|
|
|
func NewTaskfileGraph() *TaskfileGraph {
|
|
return &TaskfileGraph{
|
|
graph.New(taskfileHash,
|
|
graph.Directed(),
|
|
graph.PreventCycles(),
|
|
graph.Rooted(),
|
|
),
|
|
}
|
|
}
|
|
|
|
func (r *TaskfileGraph) Visualize(filename string) error {
|
|
f, err := os.Create(filename)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
return draw.DOT(r.Graph, f)
|
|
}
|