diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-08 09:58:02 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-08 09:58:02 +0300 |
| commit | 8e351c86502cea78f1f0b3aa19cde7ca702bacab (patch) | |
| tree | 1340e27219255b0ebe49bdbe3b5c2fbd95df8810 /cmd/do | |
| parent | 9e8f558a1f6fcdb09a8a02dfcd2e3d8fc9ce613f (diff) | |
Rename task CLI from ask to do
- Move cmd/ask to cmd/do; mage BuildDo builds binary named do
- Update askcli help text, errors, Fish completion (complete -c do, __do_*)
- Task alias cache path: XDG cache hexai/do/task-aliases-v2.json
- Refresh README and docs; go install path cmd/do@latest
- Remove accidentally tracked cmd/ask build artifact; ignore cmd/do/do and cmd/do/ask
Made-with: Cursor
Diffstat (limited to 'cmd/do')
| -rw-r--r-- | cmd/do/main.go | 22 | ||||
| -rw-r--r-- | cmd/do/main_test.go | 51 |
2 files changed, 73 insertions, 0 deletions
diff --git a/cmd/do/main.go b/cmd/do/main.go new file mode 100644 index 0000000..afab992 --- /dev/null +++ b/cmd/do/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "context" + "fmt" + "os" + + "codeberg.org/snonux/hexai/internal/askcli" +) + +func main() { + d := askcli.NewDispatcher(nil) + code, err := d.Dispatch(context.Background(), os.Args[1:], os.Stdin, os.Stdout, os.Stderr) + if err != nil { + // Print the internal error so callers get a useful diagnostic message. + fmt.Fprintln(os.Stderr, err) + os.Exit(code) + } + if code != 0 { + os.Exit(code) + } +} diff --git a/cmd/do/main_test.go b/cmd/do/main_test.go new file mode 100644 index 0000000..db6b436 --- /dev/null +++ b/cmd/do/main_test.go @@ -0,0 +1,51 @@ +package main + +import ( + "bytes" + "context" + "io" + "testing" + + "codeberg.org/snonux/hexai/internal/askcli" +) + +func TestMain_WiresDispatcher(t *testing.T) { + var gotArgs []string + 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(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) + } + if code != 0 { + t.Fatalf("exitCode = %d, want 0", code) + } + if len(gotArgs) < 1 || gotArgs[len(gotArgs)-1] != "export" { + t.Fatalf("args = %v, want [..., export]", gotArgs) + } +} + +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") + } +} + +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) +} |
