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)
This commit is contained in:
+3
-14
@@ -70,20 +70,9 @@ func runDelete(cmd *cobra.Command, args []string) error {
|
||||
fmt.Printf(" Workspace: %s\n", relPath)
|
||||
fmt.Printf(" Files: %d (%s)\n", fileCount, formatSize(totalSize))
|
||||
|
||||
// Check if this is the most recently updated workspace.
|
||||
// Spans both tasks and projects via Type=TypeAny.
|
||||
results, _ := workspace.ListWorkspaces(root, workspace.ListOpts{
|
||||
IncludeArchived: false,
|
||||
Limit: 0,
|
||||
Type: workspace.TypeAny,
|
||||
})
|
||||
if len(results) > 0 {
|
||||
best := results[0]
|
||||
for _, r := range results[1:] {
|
||||
if r.Meta.UpdatedAt.After(best.Meta.UpdatedAt) {
|
||||
best = r
|
||||
}
|
||||
}
|
||||
// Check if this is the most recently updated workspace across both
|
||||
// tasks and projects.
|
||||
if best, _ := workspace.MostRecentActive(root); best != nil {
|
||||
absBest, _ := filepath.Abs(best.Path)
|
||||
if strings.EqualFold(absTarget, absBest) {
|
||||
fmt.Println()
|
||||
|
||||
Reference in New Issue
Block a user