summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-22 20:51:38 +0200
committerPaul Buetow <paul@buetow.org>2026-03-22 20:51:38 +0200
commitb5932f24276896468ce75f9aceea2efb1fc6f44f (patch)
tree4747789a708f037c235211da6112e1cf46d88929
parent3e400433b1107274c28d6b8dd03839e442cbba0f (diff)
cmd/ask: wire to askcli.Dispatch, remove taskproxy passthrough
-rw-r--r--cmd/ask/main.go39
-rw-r--r--cmd/ask/main_test.go59
2 files changed, 35 insertions, 63 deletions
diff --git a/cmd/ask/main.go b/cmd/ask/main.go
index 73d3e04..72b67e3 100644
--- a/cmd/ask/main.go
+++ b/cmd/ask/main.go
@@ -2,45 +2,18 @@ package main
import (
"context"
- "fmt"
- "io"
"os"
- "codeberg.org/snonux/hexai/internal/taskproxy"
+ "codeberg.org/snonux/hexai/internal/askcli"
)
-type taskRunner func(context.Context, []string, io.Reader, io.Writer, io.Writer) (int, error)
-
-type askRunner struct {
- runTask taskRunner
-}
-
-func newAskRunner() askRunner {
- return askRunner{runTask: runAskTask}
-}
-
func main() {
- if exitCode := newAskRunner().run(os.Args[1:], os.Stdin, os.Stdout, os.Stderr); exitCode != 0 {
- os.Exit(exitCode)
- }
-}
-
-func (r askRunner) run(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
- runner := normalizeAskRunner(r)
- exitCode, err := runner.runTask(context.Background(), args, stdin, stdout, stderr)
+ d := askcli.NewDispatcher(nil)
+ code, err := d.Dispatch(context.Background(), os.Args[1:], os.Stdin, os.Stdout, os.Stderr)
if err != nil {
- fmt.Fprintln(stderr, err)
+ os.Exit(code)
}
- return exitCode
-}
-
-func normalizeAskRunner(r askRunner) askRunner {
- if r.runTask == nil {
- r.runTask = runAskTask
+ if code != 0 {
+ os.Exit(code)
}
- return r
-}
-
-func runAskTask(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
- return taskproxy.NewRunner("ask").Run(ctx, args, stdin, stdout, stderr)
}
diff --git a/cmd/ask/main_test.go b/cmd/ask/main_test.go
index 65551cb..f91afbd 100644
--- a/cmd/ask/main_test.go
+++ b/cmd/ask/main_test.go
@@ -3,50 +3,49 @@ package main
import (
"bytes"
"context"
- "errors"
"io"
- "reflect"
- "strings"
"testing"
+
+ "codeberg.org/snonux/hexai/internal/askcli"
)
-func TestAskRunnerRun_ForwardsArgs(t *testing.T) {
+func TestMain_WiresDispatcher(t *testing.T) {
var gotArgs []string
- var stdout bytes.Buffer
- runner := askRunner{
- runTask: func(_ context.Context, args []string, stdin io.Reader, out, errOut io.Writer) (int, error) {
+ d := askcli.NewDispatcher(&spyRunner{
+ runFn: func(_ context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
gotArgs = append([]string(nil), args...)
- _, _ = io.WriteString(out, "task output")
+ io.WriteString(stdout, `[{"uuid":"test-uuid","description":"Test","status":"pending","priority":"H","tags":["cli"],"urgency":15.0,"depends":[]}]`)
return 0, nil
},
+ })
+ code, err := d.Dispatch(context.Background(), []string{"list", "limit:1"}, nil, &bytes.Buffer{}, &bytes.Buffer{})
+ if err != nil {
+ t.Fatalf("dispatch returned error: %v", err)
}
-
- exitCode := runner.run([]string{"list", "limit:1"}, strings.NewReader(""), &stdout, &bytes.Buffer{})
- if exitCode != 0 {
- t.Fatalf("exitCode = %d, want 0", exitCode)
- }
- wantArgs := []string{"list", "limit:1"}
- if !reflect.DeepEqual(gotArgs, wantArgs) {
- t.Fatalf("args = %v, want %v", gotArgs, wantArgs)
+ if code != 0 {
+ t.Fatalf("exitCode = %d, want 0", code)
}
- if stdout.String() != "task output" {
- t.Fatalf("stdout = %q, want %q", stdout.String(), "task output")
+ if len(gotArgs) < 2 || gotArgs[0] != "export" {
+ t.Fatalf("args = %v, want [export, ...]", gotArgs)
}
}
-func TestAskRunnerRun_WritesErrorToStderr(t *testing.T) {
- var stderr bytes.Buffer
- runner := askRunner{
- runTask: func(context.Context, []string, io.Reader, io.Writer, io.Writer) (int, error) {
- return 1, errors.New("ask: must be run inside a git repository")
+func TestMain_ExitsNonZero(t *testing.T) {
+ d := askcli.NewDispatcher(&spyRunner{
+ runFn: func(context.Context, []string, io.Reader, io.Writer, io.Writer) (int, error) {
+ return 1, nil
},
+ })
+ code, _ := d.Dispatch(context.Background(), []string{"list"}, nil, &bytes.Buffer{}, &bytes.Buffer{})
+ if code == 0 {
+ t.Fatalf("exitCode = 0, want non-zero")
}
+}
- exitCode := runner.run([]string{"list"}, strings.NewReader(""), &bytes.Buffer{}, &stderr)
- if exitCode != 1 {
- t.Fatalf("exitCode = %d, want 1", exitCode)
- }
- if !strings.Contains(stderr.String(), "must be run inside a git repository") {
- t.Fatalf("stderr = %q, want actionable repo guidance", stderr.String())
- }
+type spyRunner struct {
+ runFn func(context.Context, []string, io.Reader, io.Writer, io.Writer) (int, error)
+}
+
+func (s *spyRunner) Run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) (int, error) {
+ return s.runFn(ctx, args, stdin, stdout, stderr)
}