()
| 2470 | } |
| 2471 | |
| 2472 | fn detect_install_method() -> InstallMethod { |
| 2473 | let exec_path = std::env::current_exe() |
| 2474 | .ok() |
| 2475 | .map(|p| p.to_string_lossy().to_lowercase()) |
| 2476 | .unwrap_or_default(); |
| 2477 | if exec_path.contains(".opencode/bin") || exec_path.contains(".local/bin") { |
| 2478 | return InstallMethod::Curl; |
| 2479 | } |
| 2480 | |
| 2481 | let checks: &[(InstallMethod, &str, &[&str], &str)] = &[ |
| 2482 | ( |
| 2483 | InstallMethod::Npm, |
| 2484 | "npm", |
| 2485 | &["list", "-g", "--depth=0"], |
| 2486 | "opencode-ai", |
| 2487 | ), |
| 2488 | ( |
| 2489 | InstallMethod::Pnpm, |
| 2490 | "pnpm", |
| 2491 | &["list", "-g", "--depth=0"], |
| 2492 | "opencode-ai", |
| 2493 | ), |
| 2494 | ( |
| 2495 | InstallMethod::Bun, |
| 2496 | "bun", |
| 2497 | &["pm", "ls", "-g"], |
| 2498 | "opencode-ai", |
| 2499 | ), |
| 2500 | ( |
| 2501 | InstallMethod::Brew, |
| 2502 | "brew", |
| 2503 | &["list", "--formula", "opencode"], |
| 2504 | "opencode", |
| 2505 | ), |
| 2506 | ( |
| 2507 | InstallMethod::Choco, |
| 2508 | "choco", |
| 2509 | &["list", "--limit-output", "opencode"], |
| 2510 | "opencode", |
| 2511 | ), |
| 2512 | ( |
| 2513 | InstallMethod::Scoop, |
| 2514 | "scoop", |
| 2515 | &["list", "opencode"], |
| 2516 | "opencode", |
| 2517 | ), |
| 2518 | ]; |
| 2519 | |
| 2520 | for (method, program, args, marker) in checks { |
| 2521 | if let Some(text) = command_text(program, args) { |
| 2522 | if text.to_ascii_lowercase().contains(marker) { |
| 2523 | return *method; |
| 2524 | } |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | InstallMethod::Unknown |
| 2529 | } |
no test coverage detected