summaryrefslogtreecommitdiff
path: root/internal/task/task.go
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-22 17:12:01 +0300
committerGitHub <noreply@github.com>2025-06-22 17:12:01 +0300
commit8a74c22d7a0708c79cbba40ccf85f32f568326e6 (patch)
treea7881192a026b8d4b472e5af872db40f8b3b0728 /internal/task/task.go
parent97ca49e85034cf6b57a6515407f8a73b440755ee (diff)
parent90f2d2efbf374f6ea82a46d2d701a099dbae1c89 (diff)
Merge pull request #83 from snonux/codex/fix-task-modification-bug-and-swap-hotkeys
Fix done marking bug and swap hotkeys
Diffstat (limited to 'internal/task/task.go')
-rw-r--r--internal/task/task.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/internal/task/task.go b/internal/task/task.go
index 603002d..b20eef0 100644
--- a/internal/task/task.go
+++ b/internal/task/task.go
@@ -12,6 +12,8 @@ import (
"strconv"
"strings"
"time"
+
+ "github.com/google/shlex"
)
// Task represents a taskwarrior task as returned by `task export`.
@@ -54,7 +56,7 @@ func SetDebugLog(path string) error {
// Add creates a new task with the given description and tags.
func Add(description string, tags []string) error {
- args := []string{"add"}
+ var args []string
for _, t := range tags {
if len(t) > 0 && t[0] != '+' {
t = "+" + t
@@ -62,11 +64,28 @@ func Add(description string, tags []string) error {
args = append(args, t)
}
args = append(args, description)
+ return AddArgs(args)
+}
- cmd := exec.Command("task", args...)
+// AddArgs runs "task add" with the provided arguments. Each element in args
+// is passed as a separate command-line argument, allowing the caller to
+// specify additional modifiers like due dates or tags.
+func AddArgs(args []string) error {
+ cmd := exec.Command("task", append([]string{"add"}, args...)...)
return cmd.Run()
}
+// AddLine splits the given line into shell words and runs "task add" with the
+// resulting arguments. This allows users to pass raw Taskwarrior parameters
+// such as "due:today" directly.
+func AddLine(line string) error {
+ fields, err := shlex.Split(line)
+ if err != nil {
+ return err
+ }
+ return AddArgs(fields)
+}
+
// Export retrieves all tasks using `task export rc.json.array=off` and parses
// the JSON output into a slice of Task structs.
// Export retrieves tasks using `task <filter> export rc.json.array=off` and parses