use pttodo.Todos.Like...()
This commit is contained in:
28
cmd/dump.go
28
cmd/dump.go
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"gogs.inhome.blapointe.com/bel/pttodo/pttodo"
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -31,31 +30,8 @@ func _dump(writer io.Writer, filepaths []string, tags []string, search, rootDisp
|
||||
v = root.Done
|
||||
}
|
||||
if todos, ok := v.([]pttodo.Todo); ok {
|
||||
if len(tags) > 0 {
|
||||
result := make([]pttodo.Todo, 0, len(todos))
|
||||
for _, todo := range todos {
|
||||
skip := false
|
||||
for _, tag := range tags {
|
||||
positiveTag := strings.TrimLeft(tag, "-")
|
||||
hasTag := strings.Contains(todo.Tags, positiveTag)
|
||||
wantToHaveTag := !strings.HasPrefix(tag, "-")
|
||||
skip = skip || !(hasTag == wantToHaveTag)
|
||||
}
|
||||
if !skip {
|
||||
result = append(result, todo)
|
||||
}
|
||||
}
|
||||
todos = result
|
||||
}
|
||||
if len(search) > 0 {
|
||||
result := make([]pttodo.Todo, 0, len(todos))
|
||||
for _, todo := range todos {
|
||||
if strings.Contains(strings.ToLower(fmt.Sprint(todo)), strings.ToLower(search)) {
|
||||
result = append(result, todo)
|
||||
}
|
||||
}
|
||||
todos = result
|
||||
}
|
||||
todos = pttodo.Todos(todos).LikeTags(tags)
|
||||
todos = pttodo.Todos(todos).LikeSearch(search)
|
||||
v = todos
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user