bd1cff5b26
ListOpts now exposes a Type string field (TypeAny / TypeTask / TypeProject). TypeAny is the new way to express "both tasks and projects" in a single ListWorkspaces call -- which the next two commits will use to consolidate cmd/last and cmd/delete onto a single helper, and to make 'ctask list' default to showing both types. Invalid Type values now return an explicit error from ListWorkspaces (defensive against typos in callers). cmd/list, cmd/last, and cmd/delete are migrated to the new field. External behavior is unchanged in this commit; the cleanup of ctask list semantics happens in a follow-up commit so the diff stays reviewable.
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
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",
|
|
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()
|
|
|
|
// Scan all non-archived workspaces (tasks AND projects) and find the most
|
|
// recently updated.
|
|
results, err := workspace.ListWorkspaces(root, workspace.ListOpts{
|
|
IncludeArchived: false,
|
|
Limit: 0,
|
|
Type: workspace.TypeAny,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(results) == 0 {
|
|
fmt.Fprintln(os.Stderr, "No active workspaces found.")
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Find the one with the most recent updated_at
|
|
best := results[0]
|
|
for _, r := range results[1:] {
|
|
if r.Meta.UpdatedAt.After(best.Meta.UpdatedAt) {
|
|
best = r
|
|
}
|
|
}
|
|
|
|
// Delegate to resume logic using the slug
|
|
return doResume(best.Meta.Slug, false, lastShell, lastAgent)
|
|
}
|