summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-22 19:52:08 +0200
committerPaul Buetow <paul@buetow.org>2026-03-22 19:52:08 +0200
commit9a6f6c0b747cee47eb61220d94a5fb7aaadd0e2b (patch)
tree16fa1b8a4904ddfad1cedfebfd7bcf57fa1291b9 /internal
parent23e9ab91c1e18f889eac4c0c5d5fd9daaeff7f0d (diff)
Implement 'ask urgency' subcommand: export tasks, sort by urgency descending, format as UUID table
Diffstat (limited to 'internal')
-rw-r--r--internal/askcli/command_urgency.go25
-rw-r--r--internal/askcli/command_urgency_test.go72
-rw-r--r--internal/askcli/dispatch.go4
-rw-r--r--internal/askcli/dispatch_test.go3
4 files changed, 103 insertions, 1 deletions
diff --git a/internal/askcli/command_urgency.go b/internal/askcli/command_urgency.go
new file mode 100644
index 0000000..f2be17a
--- /dev/null
+++ b/internal/askcli/command_urgency.go
@@ -0,0 +1,25 @@
+package askcli
+
+import (
+ "bytes"
+ "context"
+ "io"
+ "sort"
+)
+
+func (d Dispatcher) handleUrgency(ctx context.Context, stdout, stderr io.Writer) (int, error) {
+ var outBuf bytes.Buffer
+ code, err := d.runner.Run(ctx, []string{"export"}, nil, &outBuf, stderr)
+ if code != 0 {
+ return code, err
+ }
+ tasks, err := ParseTaskExport(&outBuf)
+ if err != nil {
+ return 1, nil
+ }
+ sort.Slice(tasks, func(i, j int) bool {
+ return tasks[i].Urgency > tasks[j].Urgency
+ })
+ io.WriteString(stdout, FormatTaskList(tasks))
+ return 0, nil
+}
diff --git a/internal/askcli/command_urgency_test.go b/internal/askcli/command_urgency_test.go
new file mode 100644
index 0000000..45ec5f5
--- /dev/null
+++ b/internal/askcli/command_urgency_test.go
@@ -0,0 +1,72 @@
+package askcli
+
+import (
+ "bytes"
+ "context"
+ "io"
+ "strings"
+ "testing"
+)
+
+func TestHandleUrgency_Success(t *testing.T) {
+ jsonData := `[{"uuid":"uuid-2","description":"Task 2","status":"pending","priority":"M","tags":["agent"],"urgency":10.0,"depends":[]},{"uuid":"uuid-1","description":"Task 1","status":"pending","priority":"H","tags":["cli"],"urgency":15.0,"depends":[]}]`
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ io.WriteString(stdout, jsonData)
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"urgency"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("urgency code = %d, want 0", code)
+ }
+ output := stdout.String()
+ lines := strings.Split(strings.TrimSpace(output), "\n")
+ if len(lines) < 4 {
+ t.Fatalf("expected at least 4 lines (header + sep + 2 tasks), got %d: %q", len(lines), output)
+ }
+ taskLine1 := lines[2]
+ taskLine2 := lines[3]
+ if !strings.Contains(taskLine1, "uuid-1") {
+ t.Fatalf("first task line should contain uuid-1 (urgency 15.0), got: %s", taskLine1)
+ }
+ if !strings.Contains(taskLine2, "uuid-2") {
+ t.Fatalf("second task line should contain uuid-2 (urgency 10.0), got: %s", taskLine2)
+ }
+}
+
+func TestHandleUrgency_EmptyList(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ io.WriteString(stdout, "[]")
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"urgency"}, nil, &stdout, &stderr)
+ if code != 0 {
+ t.Fatalf("urgency code = %d, want 0 for empty list", code)
+ }
+}
+
+func TestHandleUrgency_ExportFails(t *testing.T) {
+ d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return 1, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ code, _ := d.Dispatch(context.Background(), []string{"urgency"}, nil, &stdout, &stderr)
+ if code != 1 {
+ t.Fatalf("urgency code = %d, want 1 when export fails", code)
+ }
+}
+
+func TestHandleUrgency_PassesCorrectArgs(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
+ io.WriteString(stdout, "[]")
+ return 0, nil
+ }})
+ var stdout, stderr bytes.Buffer
+ d.Dispatch(context.Background(), []string{"urgency"}, nil, &stdout, &stderr)
+ if len(capturedArgs) != 1 || capturedArgs[0] != "export" {
+ t.Fatalf("capturedArgs = %v, want [export]", capturedArgs)
+ }
+}
diff --git a/internal/askcli/dispatch.go b/internal/askcli/dispatch.go
index 1c08aa5..b0c9e18 100644
--- a/internal/askcli/dispatch.go
+++ b/internal/askcli/dispatch.go
@@ -28,8 +28,10 @@ func (d Dispatcher) Dispatch(ctx context.Context, args []string, stdin io.Reader
}
subcommand := args[0]
switch subcommand {
- case "add", "list", "info", "dep", "urgency", "export":
+ case "add", "list", "info", "dep", "export":
return d.runner.Run(ctx, args, stdin, stdout, stderr)
+ case "urgency":
+ return d.handleUrgency(ctx, stdout, stderr)
case "annotate":
return d.handleAnnotate(ctx, args, stdout, stderr)
case "start":
diff --git a/internal/askcli/dispatch_test.go b/internal/askcli/dispatch_test.go
index 0d06299..8631f4c 100644
--- a/internal/askcli/dispatch_test.go
+++ b/internal/askcli/dispatch_test.go
@@ -76,6 +76,9 @@ func TestDispatcher_AllSubcommandsReachExecutor(t *testing.T) {
calls := 0
d := NewDispatcher(&spyRunner{runFn: func(ctx context.Context, args []string, stdin io.Reader, stdout_, stderr_ io.Writer) (int, error) {
calls++
+ if args[0] == "export" {
+ io.WriteString(stdout_, "[]")
+ }
return 0, nil
}})
args := []string{sub}