MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / format_upgrade_message

Function format_upgrade_message

atomic-cli/src/commands/update.rs:357–447  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

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

Calls 3

parentMethod · 0.80
varMethod · 0.80