summaryrefslogtreecommitdiff
path: root/internal/askcli/formatter.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-27 06:19:31 +0200
committerPaul Buetow <paul@buetow.org>2026-03-27 06:19:31 +0200
commit6b964400deb653d2c47aa8932ab5444346833b0d (patch)
treefdb9166624b91fa11cfa1e9b4a2ca3ad63bf9739 /internal/askcli/formatter.go
parentb67069c110c210b05507fca839d45b43431f5e86 (diff)
askcli: show task aliases in output (cd322ed1-882d-40e9-ab98-689acd5f161e)
Diffstat (limited to 'internal/askcli/formatter.go')
-rw-r--r--internal/askcli/formatter.go66
1 files changed, 48 insertions, 18 deletions
diff --git a/internal/askcli/formatter.go b/internal/askcli/formatter.go
index f4c0104..7ca9225 100644
--- a/internal/askcli/formatter.go
+++ b/internal/askcli/formatter.go
@@ -3,16 +3,17 @@ package askcli
import (
"fmt"
"io"
+ "slices"
"strings"
)
-func FormatTaskList(tasks []TaskExport) string {
- widths := taskListWidthsFor(tasks)
+func FormatTaskList(tasks []TaskExport, aliases map[string]string) string {
+ widths := taskListWidthsFor(tasks, aliases)
var b strings.Builder
writeTaskListHeader(&b, widths)
writeTaskListSeparator(&b, widths)
for _, t := range tasks {
- writeTaskListRow(&b, widths, t)
+ writeTaskListRow(&b, widths, t, aliases)
}
return b.String()
}
@@ -20,18 +21,18 @@ func FormatTaskList(tasks []TaskExport) string {
type taskListWidths struct {
Urgency int
Priority int
- UUID int
+ ID int
Status int
Started int
Tags int
Description int
}
-func taskListWidthsFor(tasks []TaskExport) taskListWidths {
+func taskListWidthsFor(tasks []TaskExport, aliases map[string]string) taskListWidths {
widths := taskListWidths{
Urgency: len("Urgency"),
Priority: len("Priority"),
- UUID: len("UUID"),
+ ID: len("ID"),
Status: len("Status"),
Started: len("Started"),
Tags: len("Tags"),
@@ -40,7 +41,7 @@ func taskListWidthsFor(tasks []TaskExport) taskListWidths {
for _, t := range tasks {
widths.Urgency = maxInt(widths.Urgency, len(fmt.Sprintf("%.1f", t.Urgency)))
widths.Priority = maxInt(widths.Priority, len(t.Priority))
- widths.UUID = maxInt(widths.UUID, len(t.UUID))
+ widths.ID = maxInt(widths.ID, len(displayTaskAlias(t.UUID, aliases)))
widths.Status = maxInt(widths.Status, len(t.Status))
widths.Started = maxInt(widths.Started, len(formatTaskStarted(t)))
widths.Tags = maxInt(widths.Tags, len(formatTaskTags(t.Tags)))
@@ -53,7 +54,7 @@ func writeTaskListHeader(b *strings.Builder, widths taskListWidths) {
fmt.Fprintf(b, "%-*s | %-*s | %-*s | %-*s | %-*s | %-*s | %-*s\n",
widths.Urgency, "Urgency",
widths.Priority, "Priority",
- widths.UUID, "UUID",
+ widths.ID, "ID",
widths.Status, "Status",
widths.Started, "Started",
widths.Tags, "Tags",
@@ -62,15 +63,15 @@ func writeTaskListHeader(b *strings.Builder, widths taskListWidths) {
}
func writeTaskListSeparator(b *strings.Builder, widths taskListWidths) {
- total := widths.Urgency + widths.Priority + widths.UUID + widths.Status + widths.Started + widths.Tags + widths.Description + 18
+ total := widths.Urgency + widths.Priority + widths.ID + widths.Status + widths.Started + widths.Tags + widths.Description + 18
io.WriteString(b, strings.Repeat("-", total)+"\n")
}
-func writeTaskListRow(b *strings.Builder, widths taskListWidths, t TaskExport) {
+func writeTaskListRow(b *strings.Builder, widths taskListWidths, t TaskExport, aliases map[string]string) {
fmt.Fprintf(b, "%-*s | %-*s | %-*s | %-*s | %-*s | %-*s | %-*s\n",
widths.Urgency, fmt.Sprintf("%.1f", t.Urgency),
widths.Priority, t.Priority,
- widths.UUID, t.UUID,
+ widths.ID, displayTaskAlias(t.UUID, aliases),
widths.Status, t.Status,
widths.Started, formatTaskStarted(t),
widths.Tags, formatTaskTags(t.Tags),
@@ -106,8 +107,9 @@ func maxInt(a, b int) int {
return b
}
-func FormatTaskInfo(t TaskExport) string {
+func FormatTaskInfo(t TaskExport, alias string, dependencyAliases map[string]string) string {
var b strings.Builder
+ fmt.Fprintf(&b, "ID: %s\n", alias)
fmt.Fprintf(&b, "UUID: %s\n", t.UUID)
fmt.Fprintf(&b, "Description: %s\n", t.Description)
fmt.Fprintf(&b, "Status: %s\n", t.Status)
@@ -121,7 +123,7 @@ func FormatTaskInfo(t TaskExport) string {
fmt.Fprintf(&b, "Start time: %s\n", t.Start)
}
if len(t.Depends) > 0 {
- fmt.Fprintf(&b, "Depends: %s\n", strings.Join(t.Depends, ", "))
+ fmt.Fprintf(&b, "Depends: %s\n", formatTaskDependencies(t.Depends, dependencyAliases))
}
if len(t.Annotations) > 0 {
io.WriteString(&b, "Annotations:\n")
@@ -132,17 +134,45 @@ func FormatTaskInfo(t TaskExport) string {
return b.String()
}
-func FormatSuccess(uuid string) string {
- return fmt.Sprintf("ok %s\n", uuid)
+func FormatSuccess(alias string) string {
+ return fmt.Sprintf("ok %s\n", alias)
}
-func FormatError(err error, uuid string) string {
- if uuid != "" {
- return fmt.Sprintf("error %s: %v\n", uuid, err)
+func FormatError(err error, taskID string) string {
+ if taskID != "" {
+ return fmt.Sprintf("error %s: %v\n", taskID, err)
}
return fmt.Sprintf("error: %v\n", err)
}
+func displayResolvedTaskID(resolved resolvedTaskSelector) string {
+ return displayTaskAlias(resolved.UUID, map[string]string{resolved.UUID: resolved.Alias})
+}
+
+func displayTaskAlias(uuid string, aliases map[string]string) string {
+ if alias := strings.TrimSpace(aliases[uuid]); alias != "" {
+ return alias
+ }
+ return uuid
+}
+
+func formatTaskDependencies(depends []string, aliases map[string]string) string {
+ items := make([]string, 0, len(depends))
+ for _, uuid := range depends {
+ items = append(items, formatTaskReference(uuid, aliases))
+ }
+ slices.Sort(items)
+ return strings.Join(items, ", ")
+}
+
+func formatTaskReference(uuid string, aliases map[string]string) string {
+ alias := strings.TrimSpace(aliases[uuid])
+ if alias == "" || alias == uuid {
+ return uuid
+ }
+ return fmt.Sprintf("%s (%s)", alias, uuid)
+}
+
// NormalizeUUID strips any leading "uuid:" prefix so callers can accept
// both "uuid:<value>" and bare UUID strings interchangeably. The returned
// value is always a plain UUID ready to be prefixed again when building