diff options
| author | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 18:22:36 +0300 |
|---|---|---|
| committer | Paul Bütow <1224732+snonux@users.noreply.github.com> | 2025-06-20 18:22:36 +0300 |
| commit | 7160f7669b35f89d6a4bedb46aa976ed60ebc3b9 (patch) | |
| tree | 58693754d3f99842cbb4daab8666a6359f57bfae /internal/task | |
| parent | afad8eec02ca5f0dfd37917c1d4f07399d773604 (diff) | |
Add debug logging and fix edit for started tasks
Diffstat (limited to 'internal/task')
| -rw-r--r-- | internal/task/task.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/task/task.go b/internal/task/task.go index 20a4f48..9b59cfb 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -4,9 +4,12 @@ import ( "bufio" "bytes" "encoding/json" + "fmt" + "io" "os" "os/exec" "strconv" + "strings" ) // Task represents a taskwarrior task as returned by `task export`. @@ -30,6 +33,23 @@ type Task struct { Annotations []Annotation `json:"annotations"` } +var debugWriter io.Writer + +// SetDebugLog enables logging of executed commands to the given file. +// Passing an empty path disables logging. +func SetDebugLog(path string) error { + if path == "" { + debugWriter = nil + return nil + } + f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644) + if err != nil { + return err + } + debugWriter = f + return nil +} + // Add creates a new task with the given description and tags. func Add(description string, tags []string) error { args := []string{"add"} @@ -79,6 +99,9 @@ func Export(filters ...string) ([]Task, error) { } func run(args ...string) error { + if debugWriter != nil { + fmt.Fprintln(debugWriter, "task "+strings.Join(args, " ")) + } cmd := exec.Command("task", args...) return cmd.Run() } |
