add pttodo.NewRootFromFiles

This commit is contained in:
Bel LaPointe
2023-11-06 12:58:06 -07:00
parent 3e1f58c7b9
commit bfcec9d1c5
2 changed files with 37 additions and 0 deletions

View File

@@ -13,6 +13,19 @@ type Root struct {
Done []Todo
}
func NewRootFromFiles(p ...string) (Root, error) {
var result Root
for _, p := range p {
subroot, err := NewRootFromFile(p)
if err != nil {
return Root{}, err
}
result.MergeIn(subroot)
}
result.AutoMove()
return result, nil
}
func NewRootFromFile(p string) (Root, error) {
if b, err := os.ReadFile(p); err == nil && len(bytes.TrimSpace(b)) == 0 {
return Root{}, nil