Pure business logic. Returns an `UpdateOutcome`, or a `CliError::RemoteError` for network / GitHub failures. Caller decides exit code and presentation.
(&self)
| 534 | /// `CliError::RemoteError` for network / GitHub failures. Caller |
| 535 | /// decides exit code and presentation. |
| 536 | async fn execute(&self) -> CliResult<UpdateOutcome> { |
| 537 | let env = StdEnv; |
| 538 | let source = match std::env::current_exe() { |
| 539 | Ok(p) => detect_source(&p, &env), |
| 540 | Err(_) => InstallSource::Unknown, |
| 541 | }; |
| 542 | |
| 543 | let current = env!("CARGO_PKG_VERSION").to_string(); |
| 544 | let latest_tag = fetch_latest(&env).await?; |
| 545 | let latest = latest_tag |
| 546 | .strip_prefix('v') |
| 547 | .unwrap_or(&latest_tag) |
| 548 | .to_string(); |
| 549 | |
| 550 | Ok(match (parse_version(¤t), parse_version(&latest)) { |
| 551 | (Some(c), Some(l)) if c == l => UpdateOutcome::UpToDate { current, source }, |
| 552 | (Some(c), Some(l)) if c > l => UpdateOutcome::AheadOfRelease { |
| 553 | current, |
| 554 | latest, |
| 555 | source, |
| 556 | }, |
| 557 | (Some(_), Some(_)) => { |
| 558 | let drift = match &source { |
| 559 | InstallSource::OfficialInstaller { |
| 560 | recorded_version, .. |
| 561 | } if recorded_version != ¤t => Some(recorded_version.clone()), |
| 562 | _ => None, |
| 563 | }; |
| 564 | UpdateOutcome::Outdated { |
| 565 | current, |
| 566 | latest, |
| 567 | source, |
| 568 | drift_manifest_version: drift, |
| 569 | } |
| 570 | } |
| 571 | _ => UpdateOutcome::UnknownVersion { |
| 572 | current, |
| 573 | latest, |
| 574 | source, |
| 575 | }, |
| 576 | }) |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | // Tests — inline because atomic-cli is a binary crate with no lib.rs, |
no test coverage detected