consts for what to print, default to just the todos
parent
770f2719d2
commit
96bfb96ee3
|
|
@ -17,6 +17,13 @@ import (
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DUMP_ALL = "all"
|
||||||
|
DUMP_TODO = "todo"
|
||||||
|
DUMP_SCHEDULED = "scheduled"
|
||||||
|
DUMP_DONE = "done"
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if err := _main(); err != nil {
|
if err := _main(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
@ -29,6 +36,7 @@ func _main() error {
|
||||||
defaultFilepath = "-"
|
defaultFilepath = "-"
|
||||||
}
|
}
|
||||||
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file")
|
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")
|
tags := flag.String("tags", "", "csv of all tags to find")
|
||||||
search := flag.String("search", "", "fts case insensitive")
|
search := flag.String("search", "", "fts case insensitive")
|
||||||
e := flag.Bool("e", false, "edit file")
|
e := flag.Bool("e", false, "edit file")
|
||||||
|
|
@ -43,7 +51,7 @@ func _main() error {
|
||||||
if *tags != "" {
|
if *tags != "" {
|
||||||
tagslist = strings.Split(*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 {
|
func edit(dry bool, filepath string) error {
|
||||||
|
|
@ -107,7 +115,7 @@ func edit(dry bool, filepath string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
verify := func() error {
|
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 fmt.Errorf("failed to verify %s: %v", tempFile, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -132,7 +140,7 @@ func edit(dry bool, filepath string) error {
|
||||||
return nil
|
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
|
var reader io.Reader
|
||||||
if filepath == "-" {
|
if filepath == "-" {
|
||||||
reader = os.Stdin
|
reader = os.Stdin
|
||||||
|
|
@ -156,13 +164,13 @@ func dump(dry bool, writer io.Writer, filepath, recurse string, tags []string, s
|
||||||
root.MoveScheduledToTodo()
|
root.MoveScheduledToTodo()
|
||||||
|
|
||||||
var v interface{} = root
|
var v interface{} = root
|
||||||
switch recurse {
|
switch rootDisplay {
|
||||||
case "":
|
case DUMP_ALL:
|
||||||
case "todo":
|
case DUMP_TODO:
|
||||||
v = root.Todo
|
v = root.Todo
|
||||||
case "scheduled":
|
case DUMP_SCHEDULED:
|
||||||
v = root.Scheduled
|
v = root.Scheduled
|
||||||
case "done":
|
case DUMP_DONE:
|
||||||
v = root.Done
|
v = root.Done
|
||||||
}
|
}
|
||||||
if todos, ok := v.([]pttodo.Todo); ok {
|
if todos, ok := v.([]pttodo.Todo); ok {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue