From 95081a322e45dc77c091767ed552c3d7df65e8c9 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 22 Mar 2026 20:22:43 +0200 Subject: Implement 'ask info' and 'ask add' subcommands --- internal/askcli/command_info_add.go | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 internal/askcli/command_info_add.go (limited to 'internal/askcli/command_info_add.go') diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_info_add.go new file mode 100644 index 0000000..1c937f5 --- /dev/null +++ b/internal/askcli/command_info_add.go @@ -0,0 +1,52 @@ +package askcli + +import ( + "bytes" + "context" + "io" + "strings" +) + +func (d Dispatcher) handleInfo(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) { + if len(args) < 2 { + io.WriteString(stderr, "error: ask info requires a UUID argument\n") + return 1, nil + } + uuid := args[1] + if IsNumericID(uuid) { + io.WriteString(stderr, RejectNumericID()) + return 1, nil + } + var outBuf bytes.Buffer + code, err := d.runner.Run(ctx, []string{"uuid", uuid, "export"}, nil, &outBuf, stderr) + if code != 0 { + return code, err + } + tasks, err := ParseTaskExport(&outBuf) + if err != nil || len(tasks) == 0 { + io.WriteString(stderr, "error: task not found\n") + return 1, nil + } + io.WriteString(stdout, FormatTaskInfo(tasks[0])) + return 0, nil +} + +func (d Dispatcher) handleAdd(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) { + if len(args) < 2 { + io.WriteString(stderr, "error: ask add requires a description\n") + return 1, nil + } + description := strings.Join(args[1:], " ") + var outBuf bytes.Buffer + code, err := d.runner.Run(ctx, []string{"add", description}, nil, &outBuf, stderr) + if code != 0 { + return code, err + } + createdUUID := ExtractUUIDFromOutput(outBuf.String()) + if createdUUID == "" { + io.WriteString(stderr, "error: could not extract UUID from task creation output\n") + return 1, nil + } + io.WriteString(stdout, createdUUID+"\n") + return 0, nil +} -- cgit v1.2.3