This commit is contained in:
Martin Pander
2026-03-03 21:11:58 +01:00
parent f6ce2e30dc
commit 96fbd1be65
10 changed files with 1491 additions and 297 deletions

79
cmd/tasksquire/main.go Normal file
View File

@@ -0,0 +1,79 @@
package main
import (
"context"
"log"
"log/slog"
"os"
"path/filepath"
"tasksquire/internal/common"
"tasksquire/internal/pages"
"tasksquire/internal/taskwarrior"
"tasksquire/internal/timewarrior"
//
tea "charm.land/bubbletea/v2"
)
func findTaskrc() string {
home, _ := os.UserHomeDir()
cwd, _ := os.Getwd()
searchPaths := []string{
filepath.Join(cwd, ".taskrc"),
os.Getenv("TASKRC"),
// TODO: use xdg config home envvar
filepath.Join(home, ".config/task/taskrc"),
filepath.Join(home, ".taskrc"),
}
for _, path := range searchPaths {
if path == "" {
continue
}
if _, err := os.Stat(path); err == nil {
return path
}
}
log.Fatal("Could not find taskrc in ENV, project root, or home directory")
return ""
}
func main() {
logfile, err := os.OpenFile("/tmp/tasksquire.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatalf("failed to open log file: %v", err)
}
defer logfile.Close()
handler := slog.NewTextHandler(logfile, &slog.HandlerOptions{})
slog.SetDefault(slog.New(handler))
taskrcPath := findTaskrc()
slog.Info(taskrcPath)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
taskw := taskwarrior.NewTaskwarriorInterop(ctx, taskrcPath)
if taskw == nil {
log.Fatal("Failed to initialize Taskwarrior. Please check your Taskwarrior installation and taskrc file.")
}
timew := timewarrior.NewTimewarriorInterop(ctx, "")
if timew == nil {
log.Fatal("Failed to initialize Timewarrior. Please check your Timewarrior installation and timewarrior.cfg file.")
}
common := common.NewCommon(ctx, taskw, timew)
m := pages.NewMainPage(common)
// slog.Info(m)
if _, err := tea.NewProgram(m).Run(); err != nil {
log.Fatal("Error running program:", err)
os.Exit(1)
}
}