mirror of
https://github.com/go-task/task.git
synced 2026-02-24 20:20:30 +01:00
feat(graph): add Root() helper method
Add Root() method to TaskfileGraph to get the root vertex (entrypoint Taskfile). This will be used for lazy variable resolution. Note: Tasks already have Location.Taskfile which can be used to find their source Taskfile in the graph, so GetVertexByNamespace is not needed.
This commit is contained in:
@@ -45,6 +45,18 @@ func (tfg *TaskfileGraph) Visualize(filename string) error {
|
||||
return draw.DOT(tfg.Graph, f)
|
||||
}
|
||||
|
||||
// Root returns the root vertex of the graph (the entrypoint Taskfile).
|
||||
func (tfg *TaskfileGraph) Root() (*TaskfileVertex, error) {
|
||||
hashes, err := graph.TopologicalSort(tfg.Graph)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(hashes) == 0 {
|
||||
return nil, fmt.Errorf("task: graph has no vertices")
|
||||
}
|
||||
return tfg.Vertex(hashes[0])
|
||||
}
|
||||
|
||||
func (tfg *TaskfileGraph) Merge() (*Taskfile, error) {
|
||||
hashes, err := graph.TopologicalSort(tfg.Graph)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user