Files
ctask/cmd/info.go
T
typebasedio b923ae8892 feat(v0.5.2): direct lookup includes archived; resume hint for archived
Apply the v0.5.2 lookup policy to the existing commands and wire
ValidArgsFunction hooks across the workspace-accepting surface.

info: drop the --all/-a flag entirely. Direct lookup is now
archived-inclusive by default — the user typed a name, so we find
the workspace and surface its status in the output. The Status
line already distinguishes active vs archived clearly.

resume: when targeting an archived workspace, fail with a useful
hint instead of letting the resolver report "not found":

  [ctask] error: workspace "X" is archived

  To restore it:
    ctask restore X

This is implemented by resolving archived-inclusive and rejecting
status==archived before any session-launch logic runs. Genuine
not-found and ambiguous-match behavior are unchanged.

Adds ValidArgsFunction hooks to archive (active), delete (active),
open (active), info (any), resume (active). Restore/notes/path
already have hooks from the previous commit. Shell completion now
covers the full direct-lookup surface.
2026-05-07 19:47:24 -04:00

84 lines
2.4 KiB
Go

package cmd
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
)
var infoCmd = &cobra.Command{
Use: "info <query>",
Short: "Display metadata and path for a workspace",
Args: cobra.ExactArgs(1),
SilenceUsage: true,
RunE: runInfo,
}
func init() {
infoCmd.ValidArgsFunction = completeWorkspaces(completionAny)
rootCmd.AddCommand(infoCmd)
}
func runInfo(cmd *cobra.Command, args []string) error {
// v0.5.2: info is a read-only direct lookup. Always include archived
// workspaces — if the user types a name, they want to find it whether
// or not it's archived. The status field in the output makes the state
// obvious.
roots := config.SearchRoots()
ws := resolveOne(roots, args[0], true)
m := ws.Meta
fmt.Printf("Task: %s\n", m.Slug)
fmt.Printf("Title: %s\n", m.Title)
fmt.Printf("Category: %s\n", m.Category)
fmt.Printf("Status: %s\n", m.Status)
fmt.Printf("Mode: %s\n", m.Mode)
fmt.Printf("Agent: %s\n", m.Agent)
// v0.5.1: display timestamps in local time. task.yaml stores UTC;
// info converts for friendliness so the shown time matches the user's
// wall clock.
fmt.Printf("Created: %s\n", m.CreatedAt.Local().Format("2006-01-02 15:04:05"))
fmt.Printf("Updated: %s\n", m.UpdatedAt.Local().Format("2006-01-02 15:04:05"))
fmt.Printf("Path: %s\n", ws.Path)
if m.LaunchDir != "" {
// Per spec amendment: stat the expected path directly instead of
// inferring existence from ResolveLaunch's fallback behavior. info
// is a display command, not a launch command — a permission error
// here is the same user-facing outcome as "not a directory", so
// we just report whether the stat succeeded with a directory.
launchAbs := filepath.Join(ws.Path, m.LaunchDir)
dirExists := "no"
if info, err := os.Stat(launchAbs); err == nil && info.IsDir() {
dirExists = "yes"
}
fmt.Printf("Launch dir: %s/\n", m.LaunchDir)
fmt.Printf("Launch path: %s\n", launchAbs)
fmt.Printf("Dir exists: %s\n", dirExists)
}
if m.ArchivedAt != nil {
fmt.Printf("Archived: %s\n", m.ArchivedAt.Local().Format("2006-01-02 15:04:05"))
}
// List contents
fmt.Println()
fmt.Println("Contents:")
entries, err := os.ReadDir(ws.Path)
if err != nil {
return err
}
for _, e := range entries {
name := e.Name()
if e.IsDir() {
name += "/"
}
fmt.Printf(" %s\n", name)
}
return nil
}