in prereq.go [59:118]
func loadPrereq(dir string) (tasks []string, versions []string, err error) {
err = nil
tasks = []string{}
versions = []string{}
if !exists(dir, PREREQ) {
return
}
trace("found prereq.yml in ", dir)
data, err := os.ReadFile(joinpath(dir, PREREQ))
if err != nil {
return
}
/*
You have tasks = []strings and versions = []strings
and dat a string with a YAML in format:
```yaml
something:
tasks:
task:
vars:
VERSION: "123"
anothertask:
```
I want to parse the file, find the entries under `tasks` vith a var with VERSION
and append, in order, to tasks the name of the task
and to version the version found
I have to skip the entries without a version and everyhing not in tasks
I wnato just the plain code no procedures
*/
var root yaml.Node
if err = yaml.Unmarshal([]byte(data), &root); err != nil {
return
}
for i := 0; i < len(root.Content[0].Content); i += 2 {
if root.Content[0].Content[i].Value == "tasks" {
tasksNode := root.Content[0].Content[i+1]
for j := 0; j < len(tasksNode.Content); j += 2 {
taskName := tasksNode.Content[j].Value
taskVars := tasksNode.Content[j+1]
for k := 0; k < len(taskVars.Content); k += 2 {
if taskVars.Content[k].Value == "vars" {
varsNode := taskVars.Content[k+1]
for l := 0; l < len(varsNode.Content); l += 2 {
if varsNode.Content[l].Value == "VERSION" {
version := varsNode.Content[l+1].Value
tasks = append(tasks, taskName)
versions = append(versions, version)
}
}
}
}
}
}
}
return
}