summaryrefslogtreecommitdiff
path: root/internal/askcli/command_info_add.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-23 07:41:07 +0200
committerPaul Buetow <paul@buetow.org>2026-03-23 07:41:07 +0200
commit77a38b42f47e8842e5c60673f9b25e3871cf8d8e (patch)
treee886cb0e4cd333c62f1fe9ab00661bacf719e611 /internal/askcli/command_info_add.go
parent987c08b9bd86f4e6afabfb3dcb0efaf98f1ccb38 (diff)
ask add: always emit UUID, never the numeric task ID
Use rc.verbose=new-uuid so taskwarrior prints "Created task <uuid>." directly on stdout. Parse the UUID from that line instead of doing a two-step numeric-ID lookup or falling back to an export call. Removes ExtractUUIDFromOutput (which could leak numeric IDs) and fetchUUIDByNumericID (the export fallback). Integration tests now get the UUID straight from ask add output without any extra calls. Also fixes TestMain_WiresDispatcher which expected "export" first in args, but list now prepends status:pending filter. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/askcli/command_info_add.go')
-rw-r--r--internal/askcli/command_info_add.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/internal/askcli/command_info_add.go b/internal/askcli/command_info_add.go
index 477ad62..5b76b2b 100644
--- a/internal/askcli/command_info_add.go
+++ b/internal/askcli/command_info_add.go
@@ -38,22 +38,38 @@ func (d Dispatcher) handleAdd(ctx context.Context, args []string, stdout, stderr
}
modifiers, description := parseAddArgs(args[1:])
var outBuf bytes.Buffer
- taskArgs := []string{"add"}
+ // rc.verbose=new-uuid instructs taskwarrior to emit "Created task <uuid>."
+ // so we get the UUID directly from the add output without a follow-up export.
+ taskArgs := []string{"add", "rc.verbose=new-uuid"}
taskArgs = append(taskArgs, modifiers...)
taskArgs = append(taskArgs, description)
code, err := d.runner.Run(ctx, taskArgs, 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")
+ uuid := extractUUIDFromAddOutput(outBuf.String())
+ if uuid == "" {
+ io.WriteString(stderr, "error: could not parse UUID from task creation output\n")
return 1, nil
}
- io.WriteString(stdout, createdUUID+"\n")
+ io.WriteString(stdout, uuid+"\n")
return 0, nil
}
+// extractUUIDFromAddOutput parses the UUID from taskwarrior's
+// "Created task <uuid>." output (produced when rc.verbose=new-uuid is set).
+func extractUUIDFromAddOutput(output string) string {
+ for _, line := range strings.Split(strings.TrimSpace(output), "\n") {
+ if strings.HasPrefix(line, "Created task ") {
+ parts := strings.Fields(line)
+ if len(parts) >= 3 {
+ return strings.TrimSuffix(parts[2], ".")
+ }
+ }
+ }
+ return ""
+}
+
func parseAddArgs(args []string) (modifiers []string, description string) {
for i, arg := range args {
if strings.HasPrefix(arg, "priority:") || strings.HasPrefix(arg, "+") || strings.HasPrefix(arg, "-") {