mirror of
https://github.com/go-task/task.git
synced 2025-11-25 22:32:55 +02:00
feat: add task location data to json output (#1056)
* feat: add task location data to json output * feat: add root taskfile location to --json output
This commit is contained in:
45
taskfile/tasks.go
Normal file
45
taskfile/tasks.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package taskfile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Tasks represents a group of tasks
|
||||
type Tasks map[string]*Task
|
||||
|
||||
func (t *Tasks) UnmarshalYAML(node *yaml.Node) error {
|
||||
switch node.Kind {
|
||||
case yaml.MappingNode:
|
||||
tasks := map[string]*Task{}
|
||||
if err := node.Decode(tasks); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for name := range tasks {
|
||||
// Set the task's name
|
||||
if tasks[name] == nil {
|
||||
tasks[name] = &Task{
|
||||
Task: name,
|
||||
}
|
||||
}
|
||||
tasks[name].Task = name
|
||||
|
||||
// Set the task's location
|
||||
for _, keys := range node.Content {
|
||||
if keys.Value == name {
|
||||
tasks[name].Location = &Location{
|
||||
Line: keys.Line,
|
||||
Column: keys.Column,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*t = Tasks(tasks)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("yaml: line %d: cannot unmarshal %s into tasks", node.Line, node.ShortTag())
|
||||
}
|
||||
Reference in New Issue
Block a user