test pttodo.NewRootFromFile accepts both []Todo and Root
This commit is contained in:
50
cmd/dump.go
50
cmd/dump.go
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user