Files
ctask/cmd/last.go
T
typebasedio ce742470b2 refactor(v0.3): consolidate cmd/last and cmd/delete onto MostRecentActive
Both commands now call workspace.MostRecentActive(root) directly
instead of inlining a ListWorkspaces scan + max-by-UpdatedAt loop.
The cross-type behavior is identical to before this commit (it
was already correct after the v0.3 union fix), but it is now
locked down by the focused unit tests added in the previous
commit and there is no duplicated selection logic.

The (nil, nil) "no active workspaces" return is mapped to:
  - cmd/last:   prints "No active workspaces found." and exits 1
  - cmd/delete: silently skips the "most recent" note (the user
                is deleting some specific workspace by name; the
                note was always best-effort)
2026-04-10 17:00:42 -04:00

45 lines
957 B
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
"github.com/warrenronsiek/ctask/internal/workspace"
)
var lastCmd = &cobra.Command{
Use: "last",
Short: "Resume the most recently updated workspace (task or project)",
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: runLast,
}
var (
lastShell bool
lastAgent string
)
func init() {
lastCmd.Flags().BoolVar(&lastShell, "shell", false, "Open shell instead of agent")
lastCmd.Flags().StringVarP(&lastAgent, "agent", "a", "", "Override agent command")
rootCmd.AddCommand(lastCmd)
}
func runLast(cmd *cobra.Command, args []string) error {
root := config.ResolveRoot()
best, err := workspace.MostRecentActive(root)
if err != nil {
return err
}
if best == nil {
fmt.Fprintln(os.Stderr, "No active workspaces found.")
os.Exit(1)
}
return doResume(best.Meta.Slug, false, lastShell, lastAgent)
}