From 96bfb96ee3896b7aa625692a5a25cef37221f0e8 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sat, 1 Jan 2022 17:30:40 -0500 Subject: [PATCH] consts for what to print, default to just the todos --- cmd/pttodo-cli/cli.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/pttodo-cli/cli.go b/cmd/pttodo-cli/cli.go index 24ace21..7e21ecc 100644 --- a/cmd/pttodo-cli/cli.go +++ b/cmd/pttodo-cli/cli.go @@ -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 {