consts for what to print, default to just the todos

Bel LaPointe 2022-01-01 17:30:40 -05:00
parent 770f2719d2
commit 96bfb96ee3
1 changed files with 16 additions and 8 deletions

View File

@ -17,6 +17,13 @@ import (
"gopkg.in/yaml.v2"
)
const (
DUMP_ALL = "all"
DUMP_TODO = "todo"
DUMP_SCHEDULED = "scheduled"
DUMP_DONE = "done"
)
func main() {
if err := _main(); err != nil {
panic(err)
@ -29,6 +36,7 @@ func _main() error {
defaultFilepath = "-"
}
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file")
root := flag.String("root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")")
tags := flag.String("tags", "", "csv of all tags to find")
search := flag.String("search", "", "fts case insensitive")
e := flag.Bool("e", false, "edit file")
@ -43,7 +51,7 @@ func _main() error {
if *tags != "" {
tagslist = strings.Split(*tags, ",")
}
return dump(*dry, os.Stdout, *filepath, flag.Arg(0), tagslist, *search)
return dump(*dry, os.Stdout, *filepath, tagslist, *search, *root)
}
func edit(dry bool, filepath string) error {
@ -107,7 +115,7 @@ func edit(dry bool, filepath string) error {
return nil
}
verify := func() error {
if err := dump(true, io.Discard, tempFile, "", nil, ""); err != nil {
if err := dump(true, io.Discard, tempFile, nil, "", DUMP_ALL); err != nil {
return fmt.Errorf("failed to verify %s: %v", tempFile, err)
}
return nil
@ -132,7 +140,7 @@ func edit(dry bool, filepath string) error {
return nil
}
func dump(dry bool, writer io.Writer, filepath, recurse string, tags []string, search string) error {
func dump(dry bool, writer io.Writer, filepath string, tags []string, search, rootDisplay string) error {
var reader io.Reader
if filepath == "-" {
reader = os.Stdin
@ -156,13 +164,13 @@ func dump(dry bool, writer io.Writer, filepath, recurse string, tags []string, s
root.MoveScheduledToTodo()
var v interface{} = root
switch recurse {
case "":
case "todo":
switch rootDisplay {
case DUMP_ALL:
case DUMP_TODO:
v = root.Todo
case "scheduled":
case DUMP_SCHEDULED:
v = root.Scheduled
case "done":
case DUMP_DONE:
v = root.Done
}
if todos, ok := v.([]pttodo.Todo); ok {