| 284 | } |
| 285 | |
| 286 | const char *cbm_find_cli(const char *name, const char *home_dir) { |
| 287 | static char buf[CLI_BUF_512]; |
| 288 | if (!name || !name[0]) { |
| 289 | return ""; |
| 290 | } |
| 291 | if (find_in_path(name, buf, sizeof(buf))) { |
| 292 | return buf; |
| 293 | } |
| 294 | if (!home_dir || !home_dir[0]) { |
| 295 | return ""; |
| 296 | } |
| 297 | enum { NUM_PATHS = 5 }; |
| 298 | char paths[NUM_PATHS][CLI_BUF_512]; |
| 299 | snprintf(paths[0], sizeof(paths[0]), "/usr/local/bin/%s", name); |
| 300 | snprintf(paths[1], sizeof(paths[1]), "%s/.npm/bin/%s", home_dir, name); |
| 301 | snprintf(paths[2], sizeof(paths[2]), "%s/.local/bin/%s", home_dir, name); |
| 302 | snprintf(paths[3], sizeof(paths[3]), "%s/.cargo/bin/%s", home_dir, name); |
| 303 | #ifdef __APPLE__ |
| 304 | snprintf(paths[4], sizeof(paths[4]), "/opt/homebrew/bin/%s", name); |
| 305 | #else |
| 306 | paths[4][0] = '\0'; |
| 307 | #endif |
| 308 | for (int i = 0; i < NUM_RETRIES; i++) { |
| 309 | if (paths[i][0] && is_executable(paths[i])) { |
| 310 | snprintf(buf, sizeof(buf), "%s", paths[i]); |
| 311 | return buf; |
| 312 | } |
| 313 | } |
| 314 | return ""; |
| 315 | } |
| 316 | |
| 317 | /* ── File utilities ───────────────────────────────────────────── */ |
| 318 |
no test coverage detected