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] }