(method: InstallMethod)
| 2529 | } |
| 2530 | |
| 2531 | async fn latest_version(method: InstallMethod) -> anyhow::Result<String> { |
| 2532 | let client = reqwest::Client::new(); |
| 2533 | |
| 2534 | match method { |
| 2535 | InstallMethod::Brew => { |
| 2536 | let response = client |
| 2537 | .get("https://formulae.brew.sh/api/formula/opencode.json") |
| 2538 | .send() |
| 2539 | .await?; |
| 2540 | let json: serde_json::Value = parse_http_json(response).await?; |
| 2541 | let version = json |
| 2542 | .get("versions") |
| 2543 | .and_then(|v| v.get("stable")) |
| 2544 | .and_then(|v| v.as_str()) |
| 2545 | .ok_or_else(|| anyhow::anyhow!("Unable to parse brew stable version"))?; |
| 2546 | Ok(version.to_string()) |
| 2547 | } |
| 2548 | InstallMethod::Npm | InstallMethod::Pnpm | InstallMethod::Bun => { |
| 2549 | let response = client |
| 2550 | .get("https://registry.npmjs.org/opencode-ai/latest") |
| 2551 | .send() |
| 2552 | .await?; |
| 2553 | let json: serde_json::Value = parse_http_json(response).await?; |
| 2554 | let version = json |
| 2555 | .get("version") |
| 2556 | .and_then(|v| v.as_str()) |
| 2557 | .ok_or_else(|| anyhow::anyhow!("Unable to parse npm latest version"))?; |
| 2558 | Ok(version.to_string()) |
| 2559 | } |
| 2560 | InstallMethod::Scoop => { |
| 2561 | let response = client |
| 2562 | .get("https://raw.githubusercontent.com/ScoopInstaller/Main/master/bucket/opencode.json") |
| 2563 | .send() |
| 2564 | .await?; |
| 2565 | let json: serde_json::Value = parse_http_json(response).await?; |
| 2566 | let version = json |
| 2567 | .get("version") |
| 2568 | .and_then(|v| v.as_str()) |
| 2569 | .ok_or_else(|| anyhow::anyhow!("Unable to parse scoop version"))?; |
| 2570 | Ok(version.to_string()) |
| 2571 | } |
| 2572 | _ => { |
| 2573 | let response = client |
| 2574 | .get("https://api.github.com/repos/anomalyco/opencode/releases/latest") |
| 2575 | .header("User-Agent", "opencode-cli-rust-rewrite") |
| 2576 | .send() |
| 2577 | .await?; |
| 2578 | let json: serde_json::Value = parse_http_json(response).await?; |
| 2579 | let tag = json |
| 2580 | .get("tag_name") |
| 2581 | .and_then(|v| v.as_str()) |
| 2582 | .ok_or_else(|| anyhow::anyhow!("Unable to parse latest GitHub release"))?; |
| 2583 | Ok(tag.trim_start_matches('v').to_string()) |
| 2584 | } |
| 2585 | } |
| 2586 | } |
| 2587 | |
| 2588 | fn run_upgrade_process(method: InstallMethod, target: &str) -> anyhow::Result<()> { |
no test coverage detected