From e88427ca3c9496eaf853b7e13b4b05a8ffd06121 Mon Sep 17 00:00:00 2001 From: Tink bot Date: Tue, 26 May 2026 22:40:02 +0200 Subject: [PATCH] feat(veans): add show command with PROJ-NN/#NN ID resolver --- veans/internal/commands/root.go | 1 + veans/internal/commands/show.go | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 veans/internal/commands/show.go diff --git a/veans/internal/commands/root.go b/veans/internal/commands/root.go index 5d17a3e87..0c35df120 100644 --- a/veans/internal/commands/root.go +++ b/veans/internal/commands/root.go @@ -36,6 +36,7 @@ func Root(version string) *cobra.Command { root.AddCommand(newVersionCmd(version)) root.AddCommand(newInitCmd()) root.AddCommand(newListCmd()) + root.AddCommand(newShowCmd()) return root } diff --git a/veans/internal/commands/show.go b/veans/internal/commands/show.go new file mode 100644 index 000000000..6ceac906c --- /dev/null +++ b/veans/internal/commands/show.go @@ -0,0 +1,72 @@ +package commands + +import ( + "encoding/json" + "fmt" + + "github.com/spf13/cobra" + + "code.vikunja.io/veans/internal/client" + "code.vikunja.io/veans/internal/config" + "code.vikunja.io/veans/internal/status" +) + +func newShowCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "show ", + Short: "Show a task by PROJ-NN, #NN, or numeric ID", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + rt, err := loadRuntime() + if err != nil { + return err + } + id, err := rt.resolveTaskID(cmd.Context(), args[0]) + if err != nil { + return err + } + task, err := rt.client.GetTask(cmd.Context(), id) + if err != nil { + return err + } + if globals.JSON { + return json.NewEncoder(cmd.OutOrStdout()).Encode(task) + } + renderTaskHuman(cmd.OutOrStdout(), task, rt.cfg) + return nil + }, + } + return cmd +} + +func renderTaskHuman(w fmtWriter, t *client.Task, cfg *config.Config) { + s := status.FromBucketID(t.BucketID, cfg.Buckets) + fmt.Fprintf(w, "%s %s [%s]\n", cfg.FormatTaskID(t.Index), t.Title, s) + if t.Priority > 0 { + fmt.Fprintf(w, "Priority: %d\n", t.Priority) + } + if len(t.Assignees) > 0 { + fmt.Fprintf(w, "Assignees: ") + for i, a := range t.Assignees { + if i > 0 { + fmt.Fprint(w, ", ") + } + fmt.Fprint(w, a.Username) + } + fmt.Fprintln(w) + } + if len(t.Labels) > 0 { + fmt.Fprintf(w, "Labels: ") + for i, l := range t.Labels { + if i > 0 { + fmt.Fprint(w, ", ") + } + fmt.Fprint(w, l.Title) + } + fmt.Fprintln(w) + } + if t.Description != "" { + fmt.Fprintln(w) + fmt.Fprintln(w, t.Description) + } +}