1
0
mirror of https://github.com/go-task/task.git synced 2025-11-06 09:09:13 +02:00

refactor: includes uses pointers

This commit is contained in:
Pete Davison
2024-03-29 04:29:03 +00:00
parent 24059a4b76
commit 6951e5cd0c
3 changed files with 7 additions and 7 deletions

View File

@@ -79,7 +79,7 @@ func (tfg *TaskfileGraph) Merge() (*Taskfile, error) {
} }
// Get the merge options // Get the merge options
include, ok := edge.Properties.Data.(Include) include, ok := edge.Properties.Data.(*Include)
if !ok { if !ok {
return fmt.Errorf("task: Failed to get merge options") return fmt.Errorf("task: Failed to get merge options")
} }
@@ -87,7 +87,7 @@ func (tfg *TaskfileGraph) Merge() (*Taskfile, error) {
// Merge the included Taskfile into the parent Taskfile // Merge the included Taskfile into the parent Taskfile
if err := vertex.Taskfile.Merge( if err := vertex.Taskfile.Merge(
includedVertex.Taskfile, includedVertex.Taskfile,
&include, include,
); err != nil { ); err != nil {
return err return err
} }

View File

@@ -22,7 +22,7 @@ type Include struct {
// Includes represents information about included tasksfiles // Includes represents information about included tasksfiles
type Includes struct { type Includes struct {
omap.OrderedMap[string, Include] omap.OrderedMap[string, *Include]
} }
// UnmarshalYAML implements the yaml.Unmarshaler interface. // UnmarshalYAML implements the yaml.Unmarshaler interface.
@@ -41,7 +41,7 @@ func (includes *Includes) UnmarshalYAML(node *yaml.Node) error {
return err return err
} }
v.Namespace = keyNode.Value v.Namespace = keyNode.Value
includes.Set(keyNode.Value, v) includes.Set(keyNode.Value, &v)
} }
return nil return nil
} }
@@ -58,7 +58,7 @@ func (includes *Includes) Len() int {
} }
// Wrapper around OrderedMap.Set to ensure we don't get nil pointer errors // Wrapper around OrderedMap.Set to ensure we don't get nil pointer errors
func (includes *Includes) Range(f func(k string, v Include) error) error { func (includes *Includes) Range(f func(k string, v *Include) error) error {
if includes == nil { if includes == nil {
return nil return nil
} }

View File

@@ -96,11 +96,11 @@ func (r *Reader) include(node Node) error {
var g errgroup.Group var g errgroup.Group
// Loop over each included taskfile // Loop over each included taskfile
_ = vertex.Taskfile.Includes.Range(func(namespace string, include ast.Include) error { _ = vertex.Taskfile.Includes.Range(func(namespace string, include *ast.Include) error {
// Start a goroutine to process each included Taskfile // Start a goroutine to process each included Taskfile
g.Go(func() error { g.Go(func() error {
cache := &templater.Cache{Vars: vertex.Taskfile.Vars} cache := &templater.Cache{Vars: vertex.Taskfile.Vars}
include = ast.Include{ include = &ast.Include{
Namespace: include.Namespace, Namespace: include.Namespace,
Taskfile: templater.Replace(include.Taskfile, cache), Taskfile: templater.Replace(include.Taskfile, cache),
Dir: templater.Replace(include.Dir, cache), Dir: templater.Replace(include.Dir, cache),