Produce the multi-line outdated message for a given source. Pure so the unit tests can match on substrings.
(
source: &InstallSource,
current: &str,
latest: &str,
drift_manifest_version: Option<&str>,
env: &dyn EnvLookup,
)
| 354 | /// Produce the multi-line outdated message for a given source. Pure so |
| 355 | /// the unit tests can match on substrings. |
| 356 | pub fn format_upgrade_message( |
| 357 | source: &InstallSource, |
| 358 | current: &str, |
| 359 | latest: &str, |
| 360 | drift_manifest_version: Option<&str>, |
| 361 | env: &dyn EnvLookup, |
| 362 | ) -> String { |
| 363 | let mut out = String::new(); |
| 364 | out.push_str(&format!( |
| 365 | "A new version is available: {current} -> {latest}.\n\n" |
| 366 | )); |
| 367 | |
| 368 | match source { |
| 369 | InstallSource::OfficialInstaller { |
| 370 | manifest_path, |
| 371 | recorded_install_path, |
| 372 | .. |
| 373 | } => { |
| 374 | let is_default = recorded_install_path == &PathBuf::from(DEFAULT_INSTALL_PATH); |
| 375 | if is_default { |
| 376 | out.push_str("Source: official installer\n"); |
| 377 | out.push_str(&format!(" manifest: {}\n", manifest_path.display())); |
| 378 | out.push_str(&format!( |
| 379 | " binary: {}\n\n", |
| 380 | recorded_install_path.display() |
| 381 | )); |
| 382 | out.push_str("To upgrade, re-run the installer:\n\n"); |
| 383 | out.push_str(&format!(" curl -sSf {INSTALLER_URL} | sh\n")); |
| 384 | } else { |
| 385 | let install_dir = recorded_install_path |
| 386 | .parent() |
| 387 | .map(PathBuf::from) |
| 388 | .unwrap_or_else(|| PathBuf::from("/usr/local/bin")); |
| 389 | let value = render_atomic_install_value(&install_dir, env.var("HOME").as_deref()); |
| 390 | out.push_str("Source: official installer (custom install dir)\n"); |
| 391 | out.push_str(&format!(" manifest: {}\n", manifest_path.display())); |
| 392 | out.push_str(&format!( |
| 393 | " binary: {}\n\n", |
| 394 | recorded_install_path.display() |
| 395 | )); |
| 396 | out.push_str("To upgrade, re-run the installer with the same install dir:\n\n"); |
| 397 | out.push_str(&format!( |
| 398 | " curl -sSf {INSTALLER_URL} | ATOMIC_INSTALL={value} sh\n" |
| 399 | )); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | InstallSource::Homebrew { prefix } => { |
| 404 | out.push_str(&format!( |
| 405 | "Source: Homebrew (prefix: {})\n\n", |
| 406 | prefix.display() |
| 407 | )); |
| 408 | out.push_str("To upgrade:\n\n"); |
| 409 | out.push_str(&format!(" brew upgrade {TAP_FORMULA}\n")); |
| 410 | } |
| 411 | |
| 412 | InstallSource::Cargo => { |
| 413 | out.push_str("Source: Cargo install\n\n"); |