(cwd: string, name: string)
| 149 | * Priority order: project > global > built-in |
| 150 | */ |
| 151 | export async function getCommand(cwd: string, name: string): Promise<Command | undefined> { |
| 152 | // Try to find the command directly without scanning all commands |
| 153 | const projectDir = path.join(getProjectRooDirectoryForCwd(cwd), "commands") |
| 154 | const globalDir = path.join(getGlobalRooDirectory(), "commands") |
| 155 | |
| 156 | // Check project directory first (highest priority) |
| 157 | const projectCommand = await tryLoadCommand(projectDir, name, "project") |
| 158 | if (projectCommand) { |
| 159 | return projectCommand |
| 160 | } |
| 161 | |
| 162 | // Check global directory if not found in project |
| 163 | const globalCommand = await tryLoadCommand(globalDir, name, "global") |
| 164 | if (globalCommand) { |
| 165 | return globalCommand |
| 166 | } |
| 167 | |
| 168 | // Check built-in commands if not found in project or global (lowest priority) |
| 169 | return await getBuiltInCommand(name) |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Try to load a specific command from a directory (supports symlinks) |
no test coverage detected