45 lines
854 B
Go
45 lines
854 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
|
"gopkg.in/yaml.v2"
|
|
)
|
|
|
|
func dump(config config) error {
|
|
return _dump(os.Stdout, config.Targets(), config.tags, config.search, config.root)
|
|
}
|
|
|
|
func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisplay string) error {
|
|
root, err := pttodo.NewRootFromFiles(filepaths...)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var v interface{} = root
|
|
switch rootDisplay {
|
|
case DUMP_ALL:
|
|
case DUMP_TODO:
|
|
v = root.Todo
|
|
case DUMP_SCHEDULED:
|
|
v = root.Scheduled
|
|
case DUMP_DONE:
|
|
v = root.Done
|
|
}
|
|
if todos, ok := v.([]pttodo.Todo); ok {
|
|
todos = pttodo.Todos(todos).LikeTags(tags)
|
|
todos = pttodo.Todos(todos).LikeSearch(search)
|
|
v = todos
|
|
}
|
|
|
|
b2, err := yaml.Marshal(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Fprintf(writer, "%s\n", b2)
|
|
return nil
|
|
}
|