summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 13:35:07 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 13:35:07 +0200
commitbc0849e96fe41e509af4306c0953f463a7fad155 (patch)
treeca80dd932d177bdbe9eb80cb8bffe4197d50e625
parent462184dff3eef32f01f06634305da1355ac1bec2 (diff)
fix: accept uuid: prefix on all ask subcommands via NormalizeUUID
All ask commands now strip a leading "uuid:" prefix from user-supplied UUID arguments before building the taskwarrior filter, so both bare UUIDs and the "uuid:<value>" format work uniformly across annotate, start, stop, done, modify, denotate, priority, tag, info, delete, and dep. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--internal/askcli/command_delete.go2
-rw-r--r--internal/askcli/command_dep.go6
-rw-r--r--internal/askcli/command_dep_test.go33
-rw-r--r--internal/askcli/command_info_add.go2
-rw-r--r--internal/askcli/command_list_test.go42
-rw-r--r--internal/askcli/command_write.go16
-rw-r--r--internal/askcli/command_write_test.go40
-rw-r--r--internal/askcli/formatter.go8
-rw-r--r--internal/askcli/formatter_test.go19
9 files changed, 155 insertions, 13 deletions
diff --git a/internal/askcli/command_delete.go b/internal/askcli/command_delete.go
index 84764dd..45f0f3d 100644
--- a/internal/askcli/command_delete.go
+++ b/internal/askcli/command_delete.go
@@ -11,7 +11,7 @@ func (d Dispatcher) handleDelete(ctx context.Context, args []string, stdin io.Re
io.WriteString(stderr, "error: ask delete requires a UUID argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
diff --git a/internal/askcli/command_dep.go b/internal/askcli/command_dep.go
index 6e3198c..a399c84 100644
--- a/internal/askcli/command_dep.go
+++ b/internal/askcli/command_dep.go
@@ -30,12 +30,12 @@ func (d Dispatcher) handleDepAddRm(ctx context.Context, args []string, stdout, s
io.WriteString(stderr, "error: ask dep add/rm requires <uuid> <dep-uuid>\n")
return 1, nil
}
- uuid := args[2]
+ uuid := NormalizeUUID(args[2])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
}
- depUUID := args[3]
+ depUUID := NormalizeUUID(args[3])
if IsNumericID(depUUID) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -62,7 +62,7 @@ func (d Dispatcher) handleDepList(ctx context.Context, args []string, stdout, st
io.WriteString(stderr, "error: ask dep list requires <uuid>\n")
return 1, nil
}
- uuid := args[2]
+ uuid := NormalizeUUID(args[2])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
diff --git a/internal/askcli/command_dep_test.go b/internal/askcli/command_dep_test.go
index b059dd8..6139afa 100644
--- a/internal/askcli/command_dep_test.go
+++ b/internal/askcli/command_dep_test.go
@@ -67,6 +67,39 @@ func TestHandleDep_UnknownOp(t *testing.T) {
}
}
+// TestHandleDep_AcceptUUIDPrefix verifies that dep add/rm/list accept the
+// "uuid:" prefix on both UUID arguments and strip it before building the filter.
+func TestHandleDep_AcceptUUIDPrefix(t *testing.T) {
+ testCases := []struct {
+ name string
+ args []string
+ wantArg0 string
+ }{
+ {"add with prefix", []string{"dep", "add", "uuid:uuid-1", "uuid:uuid-2"}, "uuid:uuid-1"},
+ {"rm with prefix", []string{"dep", "rm", "uuid:uuid-1", "uuid:uuid-2"}, "uuid:uuid-1"},
+ {"list with prefix", []string{"dep", "list", "uuid:uuid-1"}, "uuid:uuid-1"},
+ }
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ var capturedArgs []string
+ export := `[{"uuid":"uuid-1","description":"T","status":"pending","priority":"M","tags":[],"urgency":0,"depends":[]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ capturedArgs = args
+ io.WriteString(stdout, export)
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), tc.args, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("%s code = %d stderr = %s", tc.name, code, stderr.String())
+ }
+ if len(capturedArgs) == 0 || capturedArgs[0] != tc.wantArg0 {
+ t.Fatalf("%s capturedArgs[0] = %q, want %q (full: %v)", tc.name, capturedArgs[0], tc.wantArg0, capturedArgs)
+ }
+ })
+ }
+}
+
func TestHandleDep_NumericUUID(t *testing.T) {
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
return 0, nil
diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_info_add.go
index 5545881..0de9be5 100644
--- a/internal/askcli/command_info_add.go
+++ b/internal/askcli/command_info_add.go
@@ -12,7 +12,7 @@ func (d Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stder
io.WriteString(stderr, "error: ask info requires a UUID argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
diff --git a/internal/askcli/command_list_test.go b/internal/askcli/command_list_test.go
index e6bce83..903f397 100644
--- a/internal/askcli/command_list_test.go
+++ b/internal/askcli/command_list_test.go
@@ -68,6 +68,48 @@ func TestHandleList_EmptyList(t *testing.T) {
}
}
+func TestHandleAll_Success(t *testing.T) {
+ jsonData := `[{"uuid":"uuid-1","description":"Done task","status":"completed","priority":"M","tags":[],"urgency":0.0,"depends":[]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ for _, arg := range args {
+ if arg == "export" {
+ io.WriteString(stdout, jsonData)
+ return 0, nil
+ }
+ }
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"all"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("all code = %d, want 0", code)
+ }
+ if !strings.Contains(stdout.String(), "uuid-1") {
+ t.Fatalf("output missing uuid-1: %s", stdout.String())
+ }
+}
+
+func TestHandleReady_Success(t *testing.T) {
+ jsonData := `[{"uuid":"uuid-ready","description":"Ready task","status":"pending","priority":"H","tags":["READY"],"urgency":20.0,"depends":[]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ for _, arg := range args {
+ if arg == "export" {
+ io.WriteString(stdout, jsonData)
+ return 0, nil
+ }
+ }
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"ready"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("ready code = %d, want 0", code)
+ }
+ if !strings.Contains(stdout.String(), "uuid-ready") {
+ t.Fatalf("output missing uuid-ready: %s", stdout.String())
+ }
+}
+
func TestHandleList_PassesFilters(t *testing.T) {
var capturedArgs []string
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
diff --git a/internal/askcli/command_write.go b/internal/askcli/command_write.go
index b07ce3e..64000d7 100644
--- a/internal/askcli/command_write.go
+++ b/internal/askcli/command_write.go
@@ -12,7 +12,7 @@ func (d Dispatcher) handleDenotate(ctx context.Context, args []string, stdout, s
io.WriteString(stderr, "error: ask denotate requires a UUID and text argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -32,7 +32,7 @@ func (d Dispatcher) handleModify(ctx context.Context, args []string, stdout, std
io.WriteString(stderr, "error: ask modify requires a UUID and modification args\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -52,7 +52,7 @@ func (d Dispatcher) handleAnnotate(ctx context.Context, args []string, stdout, s
io.WriteString(stderr, "error: ask annotate requires a UUID and note argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -72,7 +72,7 @@ func (d Dispatcher) handleStart(ctx context.Context, args []string, stdout, stde
io.WriteString(stderr, "error: ask start requires a UUID argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -93,7 +93,7 @@ func (d Dispatcher) handleStop(ctx context.Context, args []string, stdout, stder
io.WriteString(stderr, "error: ask stop requires a UUID argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -112,7 +112,7 @@ func (d Dispatcher) handleDone(ctx context.Context, args []string, stdout, stder
io.WriteString(stderr, "error: ask done requires a UUID argument\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -131,7 +131,7 @@ func (d Dispatcher) handlePriority(ctx context.Context, args []string, stdout, s
io.WriteString(stderr, "error: ask priority requires a UUID and priority (H/M/L)\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
@@ -151,7 +151,7 @@ func (d Dispatcher) handleTag(ctx context.Context, args []string, stdout, stderr
io.WriteString(stderr, "error: ask tag requires a UUID and +/-tag\n")
return 1, nil
}
- uuid := args[1]
+ uuid := NormalizeUUID(args[1])
if IsNumericID(uuid) {
io.WriteString(stderr, RejectNumericID())
return 1, nil
diff --git a/internal/askcli/command_write_test.go b/internal/askcli/command_write_test.go
index 2e494db..0b6cfb5 100644
--- a/internal/askcli/command_write_test.go
+++ b/internal/askcli/command_write_test.go
@@ -233,3 +233,43 @@ func TestAllWriteHandlers_PassCorrectArgs(t *testing.T) {
})
}
}
+
+// TestAllWriteHandlers_AcceptUUIDPrefix verifies that commands accept a
+// "uuid:" prefixed argument (e.g. "uuid:my-uuid") and strip the prefix
+// before building the taskwarrior filter, so the filter is never doubled.
+func TestAllWriteHandlers_AcceptUUIDPrefix(t *testing.T) {
+ testCases := []struct {
+ subcommand string
+ args []string
+ wantArgs []string
+ }{
+ {"denotate", []string{"denotate", "uuid:my-uuid", "text"}, []string{"uuid:my-uuid", "denotate", "text"}},
+ {"modify", []string{"modify", "uuid:my-uuid", "priority:H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
+ {"annotate", []string{"annotate", "uuid:my-uuid", "note"}, []string{"uuid:my-uuid", "annotate", "note"}},
+ {"start", []string{"start", "uuid:my-uuid"}, []string{"uuid:my-uuid", "start"}},
+ {"stop", []string{"stop", "uuid:my-uuid"}, []string{"uuid:my-uuid", "stop"}},
+ {"done", []string{"done", "uuid:my-uuid"}, []string{"uuid:my-uuid", "done"}},
+ {"priority", []string{"priority", "uuid:my-uuid", "H"}, []string{"uuid:my-uuid", "modify", "priority:H"}},
+ {"tag", []string{"tag", "uuid:my-uuid", "+cli"}, []string{"uuid:my-uuid", "modify", "+cli"}},
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.subcommand, func(t *testing.T) {
+ var capturedArgs []string
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ capturedArgs = args
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ d.Dispatch(context.Background(), tc.args, &bytes.Buffer{}, &stdout, &stderr)
+ if len(capturedArgs) != len(tc.wantArgs) {
+ t.Fatalf("capturedArgs = %v, want %v", capturedArgs, tc.wantArgs)
+ }
+ for i, want := range tc.wantArgs {
+ if capturedArgs[i] != want {
+ t.Fatalf("capturedArgs[%d] = %q, want %q", i, capturedArgs[i], want)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/askcli/formatter.go b/internal/askcli/formatter.go
index 41e3b3b..886e819 100644
--- a/internal/askcli/formatter.go
+++ b/internal/askcli/formatter.go
@@ -60,6 +60,14 @@ func FormatError(err error, uuid string) string {
return fmt.Sprintf("error: %v\n", err)
}
+// NormalizeUUID strips any leading "uuid:" prefix so callers can accept
+// both "uuid:<value>" and bare UUID strings interchangeably. The returned
+// value is always a plain UUID ready to be prefixed again when building
+// taskwarrior filter arguments.
+func NormalizeUUID(s string) string {
+ return strings.TrimPrefix(s, "uuid:")
+}
+
func IsNumericID(s string) bool {
if s == "" {
return false
diff --git a/internal/askcli/formatter_test.go b/internal/askcli/formatter_test.go
index 394ea91..50d6ae3 100644
--- a/internal/askcli/formatter_test.go
+++ b/internal/askcli/formatter_test.go
@@ -106,6 +106,25 @@ func TestIsNumericID(t *testing.T) {
}
}
+func TestNormalizeUUID(t *testing.T) {
+ cases := []struct {
+ input string
+ want string
+ }{
+ {"fc390139-cc08-413f-a411-f2feae4875a3", "fc390139-cc08-413f-a411-f2feae4875a3"},
+ {"uuid:fc390139-cc08-413f-a411-f2feae4875a3", "fc390139-cc08-413f-a411-f2feae4875a3"},
+ {"fc390139", "fc390139"},
+ {"uuid:fc390139", "fc390139"},
+ {"", ""},
+ }
+ for _, c := range cases {
+ got := NormalizeUUID(c.input)
+ if got != c.want {
+ t.Errorf("NormalizeUUID(%q) = %q, want %q", c.input, got, c.want)
+ }
+ }
+}
+
func TestRejectNumericID(t *testing.T) {
output := RejectNumericID()
if !strings.Contains(output, "use UUID") {