Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50913b8913 | ||
|
|
42d532ee61 | ||
|
|
24316fe690 | ||
|
|
8058304219 | ||
|
|
7f24b3f337 | ||
|
|
fc12e0550d | ||
|
|
05f5244cd1 | ||
|
|
c559c8eba6 | ||
|
|
dd7ac8d786 | ||
|
|
ccdd2615c4 | ||
|
|
0241f2d76c | ||
|
|
fa812a16ee | ||
|
|
cf3b233a11 | ||
|
|
64868bdc0b | ||
|
|
1b1724bea7 | ||
|
|
f4968d1d1b | ||
|
|
6203ced79b | ||
|
|
4d171d10d0 | ||
|
|
8ad2ca9345 | ||
|
|
bc0bb05fb6 | ||
|
|
22dc04341c |
@@ -11,6 +11,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@@ -33,12 +34,12 @@ func main() {
|
|||||||
func _main() error {
|
func _main() error {
|
||||||
defaultFilepath, ok := os.LookupEnv("PTTODO_FILE")
|
defaultFilepath, ok := os.LookupEnv("PTTODO_FILE")
|
||||||
if !ok {
|
if !ok {
|
||||||
defaultFilepath = "-"
|
defaultFilepath = "./todo.yaml"
|
||||||
}
|
}
|
||||||
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file")
|
filepath := flag.String("f", defaultFilepath, "($PTTODO_FILE) path to yaml file or dir (starting with root then alphabetical for dir)")
|
||||||
filepathToMergeIn := flag.String("g", "", "path to yaml file to merge into -f")
|
filepathToMergeIn := flag.String("g", "", "path to yaml file to merge into -f (modifies f)")
|
||||||
root := flag.String("root", DUMP_TODO, "path to pretty print ("+fmt.Sprint([]string{DUMP_ALL, DUMP_TODO, DUMP_SCHEDULED, DUMP_DONE})+")")
|
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, -tag to invert")
|
||||||
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")
|
||||||
dry := flag.Bool("dry", false, "dry run")
|
dry := flag.Bool("dry", false, "dry run")
|
||||||
@@ -48,8 +49,17 @@ func _main() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
filepaths := []string{*filepath}
|
||||||
|
if stat, err := os.Stat(*filepath); err != nil && !os.IsNotExist(err) {
|
||||||
|
return err
|
||||||
|
} else if err == nil && stat.IsDir() {
|
||||||
|
filepaths, err = listDir(*filepath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
if *e {
|
if *e {
|
||||||
if err := edit(*dry, *filepath); err != nil {
|
if err := edit(*dry, filepaths); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +67,7 @@ func _main() error {
|
|||||||
if *tags != "" {
|
if *tags != "" {
|
||||||
tagslist = strings.Split(*tags, ",")
|
tagslist = strings.Split(*tags, ",")
|
||||||
}
|
}
|
||||||
return dump(*dry, os.Stdout, *filepath, tagslist, *search, *root)
|
return dump(*dry, os.Stdout, filepaths, tagslist, *search, *root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyRoot(root pttodo.Root) error {
|
func verifyRoot(root pttodo.Root) error {
|
||||||
@@ -79,13 +89,19 @@ func verifyRoot(root pttodo.Root) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verifyFile(path string) error {
|
func verifyFile(path string) error {
|
||||||
return dump(true, io.Discard, path, nil, "", DUMP_ALL)
|
if err := dump(true, io.Discard, []string{path}, nil, "", DUMP_ALL); err != nil {
|
||||||
|
return fmt.Errorf("failed verifying file %s: %w", path, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func edit(dry bool, filepath string) error {
|
func edit(dry bool, filepaths []string) error {
|
||||||
var tempFile string
|
tempDir, err := ioutil.TempDir(os.TempDir(), "edit-pttodo")
|
||||||
cp := func() error {
|
if err != nil {
|
||||||
f, err := ioutil.TempFile(os.TempDir(), path.Base(filepath))
|
return err
|
||||||
|
}
|
||||||
|
cpOne := func(filepath string) error {
|
||||||
|
f, err := os.Create(path.Join(tempDir, path.Base(filepath)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -100,14 +116,18 @@ func edit(dry bool, filepath string) error {
|
|||||||
g.Close()
|
g.Close()
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
tempFile = f.Name() + ".yaml"
|
return nil
|
||||||
return os.Rename(f.Name(), tempFile)
|
}
|
||||||
|
cp := func() error {
|
||||||
|
for _, filepath := range filepaths {
|
||||||
|
if err := cpOne(filepath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
vi := func() error {
|
vi := func() error {
|
||||||
bin := "vim"
|
bin := "vim"
|
||||||
if editor := os.Getenv("EDITOR"); editor != "" {
|
|
||||||
bin = editor
|
|
||||||
}
|
|
||||||
editorbin, err := exec.LookPath(bin)
|
editorbin, err := exec.LookPath(bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorbin, err = exec.LookPath("vi")
|
editorbin, err = exec.LookPath("vi")
|
||||||
@@ -115,12 +135,17 @@ func edit(dry bool, filepath string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
args := []string{editorbin, tempFile}
|
args := []string{editorbin, "-p"}
|
||||||
|
tempfiles, err := listDir(tempDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
args = append(args, tempfiles...)
|
||||||
cpid, err := syscall.ForkExec(
|
cpid, err := syscall.ForkExec(
|
||||||
editorbin,
|
editorbin,
|
||||||
args,
|
args,
|
||||||
&syscall.ProcAttr{
|
&syscall.ProcAttr{
|
||||||
Dir: "",
|
Dir: tempDir,
|
||||||
Env: os.Environ(),
|
Env: os.Environ(),
|
||||||
Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},
|
Files: []uintptr{os.Stdin.Fd(), os.Stdout.Fd(), os.Stderr.Fd()},
|
||||||
Sys: nil,
|
Sys: nil,
|
||||||
@@ -142,16 +167,61 @@ func edit(dry bool, filepath string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
verify := func() error {
|
verifyOne := func(tempFile string) error {
|
||||||
|
for {
|
||||||
|
err := verifyFile(tempFile)
|
||||||
|
if err == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Printf("%v, press <Enter> to resume editing", err)
|
||||||
|
b := make([]byte, 1)
|
||||||
|
if _, err := os.Stdin.Read(b); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if err := vi(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return verifyFile(tempFile)
|
return verifyFile(tempFile)
|
||||||
}
|
}
|
||||||
save := func() error {
|
verify := func() error {
|
||||||
|
for _, filepath := range filepaths {
|
||||||
|
tempFile := path.Join(tempDir, path.Base(filepath))
|
||||||
|
if err := verifyOne(tempFile); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
saveOne := func(filepath string) error {
|
||||||
|
tempFile := path.Join(tempDir, path.Base(filepath))
|
||||||
|
var rootTemp, rootOld pttodo.Root
|
||||||
|
if a, err := ioutil.ReadFile(tempFile); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := yaml.Unmarshal(a, &rootTemp); err != nil {
|
||||||
|
return err
|
||||||
|
} else if b, err := ioutil.ReadFile(filepath); err != nil {
|
||||||
|
return err
|
||||||
|
} else if err := yaml.Unmarshal(b, &rootOld); err != nil {
|
||||||
|
return err
|
||||||
|
} else if rootTemp.Equals(rootOld) {
|
||||||
|
//log.Printf("no changes to %s", filepath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
if dry {
|
if dry {
|
||||||
log.Printf("would've saved %s as %s", tempFile, filepath)
|
log.Printf("would've saved %s as %s", tempFile, filepath)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return os.Rename(tempFile, filepath)
|
return os.Rename(tempFile, filepath)
|
||||||
}
|
}
|
||||||
|
save := func() error {
|
||||||
|
for _, filepath := range filepaths {
|
||||||
|
if err := saveOne(filepath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, foo := range []func() error{cp, vi, verify, save} {
|
for _, foo := range []func() error{cp, vi, verify, save} {
|
||||||
if err := foo(); err != nil {
|
if err := foo(); err != nil {
|
||||||
@@ -159,7 +229,7 @@ func edit(dry bool, filepath string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !dry {
|
if !dry {
|
||||||
os.Remove(tempFile)
|
os.RemoveAll(tempDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -224,7 +294,10 @@ func marshalRootToTempFile(root pttodo.Root) (string, error) {
|
|||||||
return filepath, err
|
return filepath, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func dump(dry bool, writer io.Writer, filepath string, tags []string, search, rootDisplay string) error {
|
func dump(dry bool, writer io.Writer, filepaths []string, tags []string, search, rootDisplay string) error {
|
||||||
|
var root pttodo.Root
|
||||||
|
|
||||||
|
for _, filepath := range filepaths {
|
||||||
reader, err := filePathReader(filepath)
|
reader, err := filePathReader(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -235,10 +308,34 @@ func dump(dry bool, writer io.Writer, filepath string, tags []string, search, ro
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var root pttodo.Root
|
var root2, root2post pttodo.Root
|
||||||
if err := yaml.Unmarshal(b, &root); err != nil {
|
if err := yaml.Unmarshal(b, &root2); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := yaml.Unmarshal(b, &root2post); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
root2.MoveScheduledToTodo()
|
||||||
|
|
||||||
|
if !dry {
|
||||||
|
if !root2.Equals(root2post) {
|
||||||
|
log.Printf("refreshing %s", filepath)
|
||||||
|
b3, err := yaml.Marshal(root2)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath, b3, os.ModePerm); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//log.Printf("not refreshing %s", filepath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
root.MergeIn(root2)
|
||||||
|
}
|
||||||
|
|
||||||
root.MoveScheduledToTodo()
|
root.MoveScheduledToTodo()
|
||||||
|
|
||||||
var v interface{} = root
|
var v interface{} = root
|
||||||
@@ -255,11 +352,14 @@ func dump(dry bool, writer io.Writer, filepath string, tags []string, search, ro
|
|||||||
if len(tags) > 0 {
|
if len(tags) > 0 {
|
||||||
result := make([]pttodo.Todo, 0, len(todos))
|
result := make([]pttodo.Todo, 0, len(todos))
|
||||||
for _, todo := range todos {
|
for _, todo := range todos {
|
||||||
want := len(todo.Tags) > 0
|
skip := false
|
||||||
for _, tag := range tags {
|
for _, tag := range tags {
|
||||||
want = want && strings.Contains(todo.Tags, tag)
|
positiveTag := strings.TrimLeft(tag, "-")
|
||||||
|
hasTag := strings.Contains(todo.Tags, positiveTag)
|
||||||
|
wantToHaveTag := !strings.HasPrefix(tag, "-")
|
||||||
|
skip = skip || !(hasTag == wantToHaveTag)
|
||||||
}
|
}
|
||||||
if want {
|
if !skip {
|
||||||
result = append(result, todo)
|
result = append(result, todo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,23 +376,15 @@ func dump(dry bool, writer io.Writer, filepath string, tags []string, search, ro
|
|||||||
}
|
}
|
||||||
v = todos
|
v = todos
|
||||||
}
|
}
|
||||||
|
|
||||||
b2, err := yaml.Marshal(v)
|
b2, err := yaml.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(writer, "%s\n", b2)
|
fmt.Fprintf(writer, "%s\n", b2)
|
||||||
|
|
||||||
if dry {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
b3, err := yaml.Marshal(root)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return os.WriteFile(filepath, b3, os.ModePerm)
|
|
||||||
}
|
|
||||||
|
|
||||||
func filePathReader(path string) (io.Reader, error) {
|
func filePathReader(path string) (io.Reader, error) {
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
if path == "-" {
|
if path == "-" {
|
||||||
@@ -306,3 +398,24 @@ func filePathReader(path string) (io.Reader, error) {
|
|||||||
}
|
}
|
||||||
return reader, nil
|
return reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listDir(dname string) ([]string, error) {
|
||||||
|
entries, err := os.ReadDir(dname)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
paths := make([]string, 0, len(entries))
|
||||||
|
for i := range entries {
|
||||||
|
if entries[i].IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
paths = append(paths, path.Join(dname, entries[i].Name()))
|
||||||
|
}
|
||||||
|
sort.Slice(paths, func(i, j int) bool {
|
||||||
|
if path.Base(paths[i]) == "root.yaml" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return paths[i] < paths[j]
|
||||||
|
})
|
||||||
|
return paths, nil
|
||||||
|
}
|
||||||
|
|||||||
29
cmd/pttodo-cli/cli_test.go
Normal file
29
cmd/pttodo-cli/cli_test.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListDir(t *testing.T) {
|
||||||
|
d := t.TempDir()
|
||||||
|
want := []string{}
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
p := path.Join(d, strconv.Itoa(i))
|
||||||
|
ioutil.WriteFile(p, []byte{}, os.ModePerm)
|
||||||
|
want = append(want, p)
|
||||||
|
}
|
||||||
|
os.Mkdir(path.Join(d, "d"), os.ModePerm)
|
||||||
|
|
||||||
|
got, err := listDir(d)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if fmt.Sprint(want) != fmt.Sprint(got) {
|
||||||
|
t.Fatal(want, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
4
cmd/pttodo-cli/testdata/1.yaml
vendored
Normal file
4
cmd/pttodo-cli/testdata/1.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
todo:
|
||||||
|
- "1"
|
||||||
|
scheduled: []
|
||||||
|
done: []
|
||||||
4
cmd/pttodo-cli/testdata/2.yaml
vendored
Normal file
4
cmd/pttodo-cli/testdata/2.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
todo:
|
||||||
|
- "2"
|
||||||
|
scheduled: []
|
||||||
|
done: []
|
||||||
4
cmd/pttodo-cli/testdata/3.yaml
vendored
Normal file
4
cmd/pttodo-cli/testdata/3.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
todo:
|
||||||
|
- "3"
|
||||||
|
scheduled: []
|
||||||
|
done: []
|
||||||
4
cmd/pttodo-cli/testdata/root.yaml
vendored
Normal file
4
cmd/pttodo-cli/testdata/root.yaml
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
todo:
|
||||||
|
- root
|
||||||
|
scheduled: []
|
||||||
|
done: []
|
||||||
21
cmd/xfer/all_from_todo_server_to_pttodo.sh
Normal file
21
cmd/xfer/all_from_todo_server_to_pttodo.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
main() {
|
||||||
|
cd "$(dirname "$BASH_SOURCE")"
|
||||||
|
source ./from_todo_server_to_pttodo.sh
|
||||||
|
type from_todo_server_to_pttodo_main
|
||||||
|
list_lists | jq .list[] | jq -c . | while read -r line; do
|
||||||
|
local name="$(echo "$line" | jq -r .name | sed 's/^Today$/todo/g' | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g')"
|
||||||
|
local id="$(echo "$line" | jq -r .id)"
|
||||||
|
echo $name, $id
|
||||||
|
TODO_SERVER_LIST="$id" from_todo_server_to_pttodo_main > ./$name.yaml
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
list_lists() {
|
||||||
|
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadLists=&rnd=0.9900282499544026"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$0" == "$BASH_SOURCE" ]; then
|
||||||
|
main "$@"
|
||||||
|
fi
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
|
|
||||||
TODO_SERVER_URL="${TODO_SERVER_URL:-"https://todo-server.remote.blapointe.com"}"
|
export TODO_SERVER_URL="${TODO_SERVER_URL:-"https://todo-server.remote.blapointe.com"}"
|
||||||
TODO_SERVER_HEADERS="${TODO_SERVER_HEADERS:-"Cookie: BOAuthZ=$TODO_SERVER_BOAUTHZ"}"
|
export TODO_SERVER_HEADERS="${TODO_SERVER_HEADERS:-"Cookie: BOAuthZ=$TODO_SERVER_BOAUTHZ"}"
|
||||||
TODO_SERVER_LIST="${TODO_SERVER_LIST:-"2548023766"}"
|
export TODO_SERVER_LIST="${TODO_SERVER_LIST:-"2548023766"}"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
from_todo_server_to_pttodo_main "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
from_todo_server_to_pttodo_main() {
|
||||||
set -e
|
set -e
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
local tasks_in_todo="$(fetch_tasks_in_list | format_tasks_in_list)"
|
local tasks_in_todo="$(fetch_tasks_in_list | format_tasks_in_list)"
|
||||||
@@ -28,6 +32,10 @@ format_tasks_in_list() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetch_tasks_in_list() {
|
fetch_tasks_in_list() {
|
||||||
|
todo_server_curl "$TODO_SERVER_URL/ajax.php?loadTasks=&list=$TODO_SERVER_LIST&compl=${COMPL:-0}&looping=${LOOPING:-0}"
|
||||||
|
}
|
||||||
|
|
||||||
|
todo_server_curl() {
|
||||||
local csv_headers="$TODO_SERVER_HEADERS"
|
local csv_headers="$TODO_SERVER_HEADERS"
|
||||||
local headers=()
|
local headers=()
|
||||||
while [ "$csv_headers" != "" ]; do
|
while [ "$csv_headers" != "" ]; do
|
||||||
@@ -39,7 +47,7 @@ fetch_tasks_in_list() {
|
|||||||
csv_headers=""
|
csv_headers=""
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
curl -sS "${headers[@]}" "$TODO_SERVER_URL/ajax.php?loadTasks=&list=$TODO_SERVER_LIST&compl=${COMPL:-0}&looping=${LOOPING:-0}"
|
curl -sS "${headers[@]}" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$0" == "$BASH_SOURCE" ]; then
|
if [ "$0" == "$BASH_SOURCE" ]; then
|
||||||
|
|||||||
@@ -6,6 +6,20 @@ type Root struct {
|
|||||||
Done []Todo
|
Done []Todo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (root Root) Equals(other Root) bool {
|
||||||
|
for i, slice := range [][2][]Todo{
|
||||||
|
[2][]Todo{root.Todo, other.Todo},
|
||||||
|
[2][]Todo{root.Scheduled, other.Scheduled},
|
||||||
|
[2][]Todo{root.Done, other.Done},
|
||||||
|
} {
|
||||||
|
_ = i
|
||||||
|
if !equalTodoSlices(slice[0], slice[1]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (root *Root) MoveScheduledToTodo() {
|
func (root *Root) MoveScheduledToTodo() {
|
||||||
for i := len(root.Scheduled) - 1; i >= 0; i-- {
|
for i := len(root.Scheduled) - 1; i >= 0; i-- {
|
||||||
if root.Scheduled[i].Triggered() {
|
if root.Scheduled[i].Triggered() {
|
||||||
@@ -36,3 +50,17 @@ func (root *Root) MergeIn(root2 Root) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (root Root) MarshalYAML() (interface{}, error) {
|
||||||
|
for i := range root.Todo {
|
||||||
|
root.Todo[i].writeTS = false
|
||||||
|
}
|
||||||
|
for i := range root.Scheduled {
|
||||||
|
root.Scheduled[i].writeTS = true
|
||||||
|
}
|
||||||
|
for i := range root.Done {
|
||||||
|
root.Done[i].writeTS = true
|
||||||
|
}
|
||||||
|
type Alt Root
|
||||||
|
return (Alt)(root), nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -23,6 +24,8 @@ func TestJSONRoot(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if fmt.Sprint(root) != fmt.Sprint(root2) {
|
} else if fmt.Sprint(root) != fmt.Sprint(root2) {
|
||||||
t.Fatal(root, root2)
|
t.Fatal(root, root2)
|
||||||
|
} else if !root.Equals(root2) {
|
||||||
|
t.Fatal(root2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +97,8 @@ func TestRootMoveScheduledToTodo(t *testing.T) {
|
|||||||
got.MoveScheduledToTodo()
|
got.MoveScheduledToTodo()
|
||||||
if fmt.Sprintf("%+v", got) != fmt.Sprintf("%+v", want) {
|
if fmt.Sprintf("%+v", got) != fmt.Sprintf("%+v", want) {
|
||||||
t.Fatalf("want \n\t%+v, got \n\t%+v", want, got)
|
t.Fatalf("want \n\t%+v, got \n\t%+v", want, got)
|
||||||
|
} else if !got.Equals(want) {
|
||||||
|
t.Fatalf("want \n\t%+v, got \n\t%+v", want, got)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -143,5 +148,32 @@ todo:
|
|||||||
root0.MergeIn(root1)
|
root0.MergeIn(root1)
|
||||||
if fmt.Sprintf("%+v", root0) != fmt.Sprintf("%+v", rootWant) {
|
if fmt.Sprintf("%+v", root0) != fmt.Sprintf("%+v", rootWant) {
|
||||||
t.Fatalf("want \n\t%+v, got \n\t%+v", rootWant, root0)
|
t.Fatalf("want \n\t%+v, got \n\t%+v", rootWant, root0)
|
||||||
|
} else if !root0.Equals(rootWant) {
|
||||||
|
t.Fatalf("want \n\t%+v, got \n\t%+v", rootWant, root0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRootMarshalYAMLWriteTS(t *testing.T) {
|
||||||
|
root := Root{
|
||||||
|
Todo: []Todo{Todo{Todo: "todo", TS: 1, writeTS: true}},
|
||||||
|
Scheduled: []Todo{Todo{Todo: "sched", TS: 2, writeTS: false, Schedule: "2099-01-01"}},
|
||||||
|
Done: []Todo{Todo{Todo: "done", TS: 3, writeTS: false}},
|
||||||
|
}
|
||||||
|
got, err := yaml.Marshal(root)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(string(got)) != strings.TrimSpace(`
|
||||||
|
todo:
|
||||||
|
- todo
|
||||||
|
scheduled:
|
||||||
|
- todo: sched
|
||||||
|
schedule: "2099-01-01"
|
||||||
|
ts: Wed Dec 31 19:00:02 EST 1969
|
||||||
|
done:
|
||||||
|
- todo: done
|
||||||
|
ts: Wed Dec 31 19:00:03 EST 1969
|
||||||
|
`) {
|
||||||
|
t.Fatal(string(got))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,8 +94,11 @@ func (due scheduleDue) next(time.Time) (time.Time, error) {
|
|||||||
// 2022-01-01
|
// 2022-01-01
|
||||||
type scheduleEZDate string
|
type scheduleEZDate string
|
||||||
|
|
||||||
var scheduleEZDatePattern = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}-[0-9]{2}$`)
|
var scheduleEZDatePattern = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2})?$`)
|
||||||
|
|
||||||
func (ezdate scheduleEZDate) next(time.Time) (time.Time, error) {
|
func (ezdate scheduleEZDate) next(time.Time) (time.Time, error) {
|
||||||
return time.Parse("2006-01-02", string(ezdate))
|
if len(ezdate) == len("20xx-xx-xxTxx") {
|
||||||
|
return time.ParseInLocation("2006-01-02T15", string(ezdate), time.Local)
|
||||||
|
}
|
||||||
|
return time.ParseInLocation("2006-01-02", string(ezdate), time.Local)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,11 +51,17 @@ func TestJSONSchedule(t *testing.T) {
|
|||||||
func TestSchedulerFactory(t *testing.T) {
|
func TestSchedulerFactory(t *testing.T) {
|
||||||
start := time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC)
|
start := time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC)
|
||||||
someDay := time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC)
|
someDay := time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC)
|
||||||
|
someHour := time.Date(2001, 2, 3, 15, 0, 0, 0, time.UTC)
|
||||||
cases := map[string]struct {
|
cases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
want interface{}
|
want interface{}
|
||||||
next time.Time
|
next time.Time
|
||||||
}{
|
}{
|
||||||
|
"ezdate with hour": {
|
||||||
|
input: `2000-01-03T15`,
|
||||||
|
want: scheduleEZDate(`2000-01-03T15`),
|
||||||
|
next: someHour,
|
||||||
|
},
|
||||||
"long dur": {
|
"long dur": {
|
||||||
input: `2h1m`,
|
input: `2h1m`,
|
||||||
want: scheduleDuration("2h1m"),
|
want: scheduleDuration("2h1m"),
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import (
|
|||||||
|
|
||||||
type Todo struct {
|
type Todo struct {
|
||||||
Todo string
|
Todo string
|
||||||
TS TS
|
|
||||||
Details string `yaml:",omitempty"`
|
Details string `yaml:",omitempty"`
|
||||||
Schedule Schedule `yaml:",omitempty"`
|
Schedule Schedule `yaml:",omitempty"`
|
||||||
Tags string `yaml:",omitempty"`
|
Tags string `yaml:",omitempty"`
|
||||||
Subtasks []Todo `yaml:",omitempty"`
|
Subtasks []Todo `yaml:",omitempty"`
|
||||||
|
TS TS `yaml:",omitempty"`
|
||||||
|
writeTS bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (todo Todo) Triggered() bool {
|
func (todo Todo) Triggered() bool {
|
||||||
@@ -21,6 +22,11 @@ func (todo Todo) Triggered() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (todo Todo) MarshalYAML() (interface{}, error) {
|
func (todo Todo) MarshalYAML() (interface{}, error) {
|
||||||
|
if !todo.writeTS {
|
||||||
|
todo.TS = 0
|
||||||
|
} else {
|
||||||
|
todo.TS = TS(todo.TS.time().Unix())
|
||||||
|
}
|
||||||
if fmt.Sprint(todo) == fmt.Sprint(Todo{Todo: todo.Todo}) {
|
if fmt.Sprint(todo) == fmt.Sprint(Todo{Todo: todo.Todo}) {
|
||||||
return todo.Todo, nil
|
return todo.Todo, nil
|
||||||
}
|
}
|
||||||
@@ -37,3 +43,37 @@ func (todo *Todo) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|||||||
alt := (*Alt)(todo)
|
alt := (*Alt)(todo)
|
||||||
return unmarshal(alt)
|
return unmarshal(alt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (todo Todo) Equals(other Todo) bool {
|
||||||
|
if !equalTodoSlices(todo.Subtasks, other.Subtasks) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if todo.TS != other.TS {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if todo.Tags != other.Tags {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if todo.Schedule != other.Schedule {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if todo.Details != other.Details {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if todo.Todo != other.Todo {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func equalTodoSlices(a, b []Todo) bool {
|
||||||
|
if len(a) != len(b) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := range a {
|
||||||
|
if !a[i].Equals(b[i]) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (ts *TS) UnmarshalYAML(unmarshaller func(interface{}) error) error {
|
|||||||
}
|
}
|
||||||
var s string
|
var s string
|
||||||
if err := unmarshaller(&s); err == nil {
|
if err := unmarshaller(&s); err == nil {
|
||||||
t, err := time.Parse(time.UnixDate, s)
|
t, err := time.ParseInLocation(time.UnixDate, s, time.Local)
|
||||||
*ts = TS(t.Unix())
|
*ts = TS(t.Unix())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
97
todo.yaml
97
todo.yaml
@@ -1,18 +1,12 @@
|
|||||||
todo:
|
todo:
|
||||||
- merge multi todo files for 'inbox' style with some dedupe
|
- when merging, check for complete/incomplete and cross reference todo vs scheduled
|
||||||
|
vs done
|
||||||
- click on links when dumped via cli
|
- click on links when dumped via cli
|
||||||
- what do about todo-now vs todo vs watch vs later... could do many files and manage
|
scheduled: []
|
||||||
outside binary, but search would suck. Good would be vendor lockin, and that's UI problem
|
done:
|
||||||
- add tag anti-search, like -tag=-notMe
|
- xactions emails extend ledger,todo-server with pttodo - schedule merge inbox style
|
||||||
- todo: when to run scheduled modifier? like, syncthing could have conflicts if I
|
- xactions emails extend ledger,todo-server with pttodo
|
||||||
modify only file on remote
|
|
||||||
ts: Fri Dec 31 22:33:12 EST 2021
|
|
||||||
details: |
|
|
||||||
- if it's a web ui hook or somethin, then it'd only have file conflict if I modify without waiting
|
|
||||||
- but thats a step back from current todo solution
|
|
||||||
tags: stuffToTry,secondTag
|
|
||||||
- todo: ez edit on many platforms, even offline and mobile
|
- todo: ez edit on many platforms, even offline and mobile
|
||||||
ts: Fri Dec 31 22:33:12 EST 2021
|
|
||||||
details: |
|
details: |
|
||||||
mobile view + complete method
|
mobile view + complete method
|
||||||
collab editing of file prob resolves mobile and other stuff...
|
collab editing of file prob resolves mobile and other stuff...
|
||||||
@@ -20,38 +14,69 @@ todo:
|
|||||||
web server access to ops
|
web server access to ops
|
||||||
is a web ui for mobile best solution?
|
is a web ui for mobile best solution?
|
||||||
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
||||||
scheduled: []
|
- todo: when to run scheduled modifier? like, syncthing could have conflicts if I
|
||||||
done:
|
modify only file on remote
|
||||||
- more schedule formats, like just 2022-01-15, for deferring
|
details: |
|
||||||
- from todo-server to pttodo format
|
- if it's a web ui hook or somethin, then it'd only have file conflict if I modify without waiting
|
||||||
- add -tag to search via cli
|
- but thats a step back from current todo solution
|
||||||
- ts to human readable
|
tags: stuffToTry,secondTag
|
||||||
- here is my really here is my really here is my really here is my really here is
|
- what do about todo-now vs todo vs watch vs later... could do many files and manage
|
||||||
my really here is my really here is my really here is my really here is my really
|
outside binary, but search would suck. Good would be vendor lockin, and that's UI
|
||||||
here is my really here is my really here is my really here is my really here is
|
problem
|
||||||
my really here is my really long string
|
- merge multi todo files for 'inbox' style with some dedupe (probably best to just
|
||||||
- vim doesnt source vimrc, so stuff like tab width and tab characters, also syntax
|
do this via calling pttodo-cli from script or somethin) (probably at an off hour
|
||||||
highlight :(
|
so no collisions from live editing)
|
||||||
- crontab -e style editing to ensure good syntax
|
- how to defer a scheduled task?
|
||||||
|
- todo: add tag anti-search, like -tag=-notMe
|
||||||
|
ts: Tue Jan 4 06:56:03 EST 2022
|
||||||
|
- todo: if in todo, then omit ts field
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: merge full files to import from todo-server
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: more schedule formats, like just 2022-01-15, for deferring
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: from todo-server to pttodo format
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: add -tag to search via cli
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: ts to human readable
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: here is my really here is my really here is my really here is my really here
|
||||||
|
is my really here is my really here is my really here is my really here is my
|
||||||
|
really here is my really here is my really here is my really here is my really
|
||||||
|
here is my really here is my really long string
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: vim doesnt source vimrc, so stuff like tab width and tab characters, also
|
||||||
|
syntax highlight :(
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: crontab -e style editing to ensure good syntax
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
- todo: YAML based todo
|
- todo: YAML based todo
|
||||||
ts: Fri Dec 31 22:33:12 EST 2021
|
|
||||||
details: because goddamnit a year of this shit isn't significant on disk or in RAM
|
details: because goddamnit a year of this shit isn't significant on disk or in RAM
|
||||||
for vim
|
for vim
|
||||||
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
- todo: yaml based todo for plaintext
|
- todo: yaml based todo for plaintext
|
||||||
ts: Fri Dec 31 22:33:12 EST 2021
|
|
||||||
details: a year isnt even a mb
|
details: a year isnt even a mb
|
||||||
- ez edit, start on many platforms
|
|
||||||
- defer
|
|
||||||
- schedule
|
|
||||||
- looping
|
|
||||||
- details
|
|
||||||
- let UI be UI for whatever platform
|
|
||||||
- tags
|
|
||||||
- todo: sub tasks
|
|
||||||
ts: Fri Dec 31 22:33:12 EST 2021
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
|
- todo: ez edit, start on many platforms
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: defer
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: schedule
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: looping
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: details
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: let UI be UI for whatever platform
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: tags
|
||||||
|
ts: Sun Jan 2 20:44:27 EST 2022
|
||||||
|
- todo: sub tasks
|
||||||
subtasks:
|
subtasks:
|
||||||
- a
|
- a
|
||||||
|
ts: Fri Dec 31 22:33:12 EST 2021
|
||||||
- todo: crap losing on a bad edit hurts
|
- todo: crap losing on a bad edit hurts
|
||||||
ts: Fri Dec 31 22:37:58 EST 2021
|
|
||||||
details: |
|
details: |
|
||||||
?
|
?
|
||||||
|
ts: Fri Dec 31 22:37:58 EST 2021
|
||||||
|
|||||||
Reference in New Issue
Block a user