(ctx context.Context, ref string)
| 3226 | } |
| 3227 | |
| 3228 | func (c *unixSocketClient) workspaceRouteRef(ctx context.Context, ref string) (string, error) { |
| 3229 | trimmed := strings.TrimSpace(ref) |
| 3230 | if trimmed == "" { |
| 3231 | return "", errors.New("cli: workspace reference is required") |
| 3232 | } |
| 3233 | if !workspaceRefLooksLikePath(trimmed) { |
| 3234 | return trimmed, nil |
| 3235 | } |
| 3236 | target, err := canonicalCLIWorkspacePath(trimmed) |
| 3237 | if err != nil { |
| 3238 | return "", err |
| 3239 | } |
| 3240 | workspaces, err := c.ListWorkspaces(ctx) |
| 3241 | if err != nil { |
| 3242 | return "", fmt.Errorf("cli: list workspaces before resolving path %q: %w", target, err) |
| 3243 | } |
| 3244 | for _, workspace := range workspaces { |
| 3245 | root, err := canonicalCLIWorkspacePath(workspace.RootDir) |
| 3246 | if err != nil { |
| 3247 | continue |
| 3248 | } |
| 3249 | if root == target { |
| 3250 | return workspace.ID, nil |
| 3251 | } |
| 3252 | } |
| 3253 | return "", fmt.Errorf("cli: workspace path %q is not registered", target) |
| 3254 | } |
| 3255 | |
| 3256 | func workspaceRefLooksLikePath(ref string) bool { |
| 3257 | return filepath.IsAbs(ref) || |
no test coverage detected