test pttodo.NewRootFromFile accepts both []Todo and Root

This commit is contained in:
Bel LaPointe
2023-11-06 12:54:46 -07:00
parent 92e8e14c08
commit 3e1f58c7b9
3 changed files with 66 additions and 48 deletions

View File

@@ -3,10 +3,7 @@ package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
@@ -20,54 +17,13 @@ func dump(config config) error {
func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisplay string) error {
var root pttodo.Root
for _, p := range filepaths {
results, err := filepath.Glob(p + ".*")
if err != nil {
return err
}
for _, result := range results {
if result == p {
continue
}
filepaths = append(filepaths, result)
}
}
for _, filepath := range filepaths {
reader, err := filePathReader(filepath)
subroot, err := pttodo.NewRootFromFile(filepath)
if err != nil {
return err
}
b, err := ioutil.ReadAll(reader)
if err != nil {
return err
}
var root2, root2post pttodo.Root
if err := yaml.Unmarshal(b, &root2); err != nil {
return err
}
if err := yaml.Unmarshal(b, &root2post); err != nil {
return err
}
root2.MoveScheduledToTodo()
if !root2.Equals(root2post) {
log.Printf("refreshing %s", filepath)
b3, err := yaml.Marshal(root2)
if err != nil {
return err
}
if err := os.WriteFile(filepath, b3, os.ModePerm); err != nil {
return err
}
} else {
//log.Printf("not refreshing %s", filepath)
}
root.MergeIn(root2)
subroot.MoveScheduledToTodo()
root.MergeIn(subroot)
}
root.MoveScheduledToTodo()