summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-22 16:39:56 +0300
committerPaul Bütow <1224732+snonux@users.noreply.github.com>2025-06-22 16:39:56 +0300
commitdc1a6e83669dd22be4542833970d3251741ba1f3 (patch)
treee2585f906485e89f6d4417a5d1d3d04f9c442ce4 /internal
parente42bb79ed74cb975db0c4b8128b9014f0f6acf33 (diff)
Fix add task hotkey
Diffstat (limited to 'internal')
-rw-r--r--internal/task/task.go23
-rw-r--r--internal/ui/table.go2
-rw-r--r--internal/ui/table_test.go4
3 files changed, 24 insertions, 5 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
diff --git a/internal/ui/table.go b/internal/ui/table.go
index 482d89e..c3e1748 100644
--- a/internal/ui/table.go
+++ b/internal/ui/table.go
@@ -484,7 +484,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
for _, tsk := range m.tasks {
oldIDs[tsk.ID] = struct{}{}
}
- task.Add(m.addInput.Value(), nil)
+ task.AddLine(m.addInput.Value())
m.addingTask = false
m.addInput.Blur()
m.reload()
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index f378973..365180c 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -476,7 +476,7 @@ func TestAddHotkey(t *testing.T) {
mv, _ := m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'+'}})
m = mv.(Model)
- for _, r := range "task" {
+ for _, r := range "foo due:today" {
mv, _ = m.Update(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{r}})
m = mv.(Model)
}
@@ -488,7 +488,7 @@ func TestAddHotkey(t *testing.T) {
t.Fatalf("read add: %v", err)
}
- if strings.TrimSpace(string(data)) != "add task" {
+ if strings.TrimSpace(string(data)) != "add foo due:today" {
t.Fatalf("add not called: %q", data)
}
}