summaryrefslogtreecommitdiff
path: root/internal/task/task.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/task/task.go')
-rw-r--r--internal/task/task.go23
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()
}