Skip to content

Commit 1163cca

Browse files
committed
fix: show '(built-in)' instead of '(installed)' for commands without version info
When a command exists in PATH but doesn't provide a parseable version, display 'path: installed (built-in)' instead of the confusing 'path: installed (installed)'.
1 parent 3955993 commit 1163cca

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "latest"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2024"
55
description = "Find the latest version of any command, package, or library"
66
license = "MIT"

src/main.rs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,17 @@ fn format_result(r: &PackageResult, show_name: bool) -> String {
347347
match r.status {
348348
Status::UpToDate => {
349349
let info = r.installed.as_ref().unwrap();
350-
let installed_marker = if info.local { " (installed)" } else { "" };
350+
let installed_marker = if info.local {
351+
if info.version == "installed" { " (built-in)" } else { " (installed)" }
352+
} else { "" };
351353
format!("{pkg_prefix}{}: {}{}", info.source, info.version, installed_marker)
352354
}
353355
Status::Outdated => {
354356
let installed = r.installed.as_ref().unwrap();
355357
let latest = &r.latest.as_ref().unwrap().version;
356-
let installed_marker = if installed.local { " (installed)" } else { "" };
358+
let installed_marker = if installed.local {
359+
if installed.version == "installed" { " (built-in)" } else { " (installed)" }
360+
} else { "" };
357361
format!(
358362
"{pkg_prefix}{}: {}{} → {} available",
359363
installed.source, installed.version, installed_marker, latest
@@ -399,7 +403,9 @@ fn output_results(cli: &Cli, results: &[PackageResult]) {
399403
eprintln!("{}", if results.len() > 1 { " not found" } else { "not found" });
400404
} else {
401405
for v in &r.available {
402-
let mark = if v.local { " (installed)" } else { "" };
406+
let mark = if v.local {
407+
if v.version == "installed" { " (built-in)" } else { " (installed)" }
408+
} else { "" };
403409
let line = format!("{}: {}{}", v.source, v.version, mark);
404410
println!("{}", if results.len() > 1 { format!(" {line}") } else { line });
405411
}
@@ -754,4 +760,44 @@ mod tests {
754760
assert_eq!(r.available.len(), 2);
755761
assert!(r.available.iter().all(|v| v.local));
756762
}
763+
764+
// ─────────────────────────────────────────────────────────────────────────
765+
// Format result tests
766+
// ─────────────────────────────────────────────────────────────────────────
767+
768+
#[test]
769+
fn test_format_result_builtin_command() {
770+
// When version is "installed" (unknown version), show "(built-in)" not "(installed)"
771+
let r = PackageResult::up_to_date(
772+
"ping",
773+
VersionInfo { version: "installed".to_string(), source: "path".to_string(), local: true },
774+
vec![],
775+
);
776+
let output = format_result(&r, false);
777+
assert_eq!(output, "path: installed (built-in)");
778+
}
779+
780+
#[test]
781+
fn test_format_result_installed_with_version() {
782+
// When we have an actual version, show "(installed)"
783+
let r = PackageResult::up_to_date(
784+
"node",
785+
VersionInfo { version: "22.0.0".to_string(), source: "path".to_string(), local: true },
786+
vec![],
787+
);
788+
let output = format_result(&r, false);
789+
assert_eq!(output, "path: 22.0.0 (installed)");
790+
}
791+
792+
#[test]
793+
fn test_format_result_network_source_no_marker() {
794+
// Network sources don't get any marker
795+
let r = PackageResult::up_to_date(
796+
"express",
797+
VersionInfo { version: "5.0.0".to_string(), source: "npm".to_string(), local: false },
798+
vec![],
799+
);
800+
let output = format_result(&r, false);
801+
assert_eq!(output, "npm: 5.0.0");
802+
}
757803
}

0 commit comments

Comments
 (0)