Files
ctask/cmd/helpers.go
T
typebasedio 0c1f03ba3a fix(v0.4.1): route all workspace commands through SearchRoots
Every resolver, lister, and most-recent caller now passes
config.SearchRoots() so CTASK_PROJECT_ROOT is searched alongside
CTASK_ROOT. Commands use ws.Root when rendering relative paths or
session env vars so displays and CTASK_ROOT exports are correct for
workspaces living under CTASK_PROJECT_ROOT.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 17:54:58 -04:00

36 lines
966 B
Go

package cmd
import (
"fmt"
"os"
"github.com/warrenronsiek/ctask/internal/workspace"
)
// resolveOne resolves a query to exactly one workspace across the given roots.
// Prints errors and exits on 0 or >1 matches. Callers typically pass
// config.SearchRoots() so both CTASK_ROOT and CTASK_PROJECT_ROOT are searched.
func resolveOne(roots []string, query string, includeArchived bool) *workspace.QueryResult {
results, err := workspace.ResolveQuery(roots, query, includeArchived)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
if len(results) == 0 {
fmt.Fprintf(os.Stderr, "No workspace matches %q.\n", query)
os.Exit(1)
}
if len(results) > 1 {
fmt.Fprintf(os.Stderr, "Multiple workspaces match %q:\n", query)
for _, r := range results {
fmt.Fprintf(os.Stderr, " %s\n", workspace.RelativePath(r.Root, r.Path))
}
fmt.Fprintln(os.Stderr, "Specify a more precise query.")
os.Exit(1)
}
return &results[0]
}