MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / is_command_installed

Function is_command_installed

src/binary_installer/mod.rs:66–97  ·  view source on GitHub ↗

Check if the given command is installed and its version matches the expected version. Expects the command to support the `--version` flag and return a version string.

(command: &str, expected_version: Version)

Source from the content-addressed store, hash-verified

64///
65/// Expects the command to support the `--version` flag and return a version string.
66fn is_command_installed(command: &str, expected_version: Version) -> bool {
67 let is_command_installed = Command::new("which")
68 .arg(command)
69 .output()
70 .is_ok_and(|output| output.status.success());
71
72 if !is_command_installed {
73 debug!("{command} is not installed");
74 return false;
75 }
76
77 let Ok(version_output) = Command::new(command).arg("--version").output() else {
78 return false;
79 };
80
81 if !version_output.status.success() {
82 debug!(
83 "Failed to get command version. stderr: {}",
84 String::from_utf8_lossy(&version_output.stderr)
85 );
86 return false;
87 }
88
89 let version_string = String::from_utf8_lossy(&version_output.stdout);
90 let Ok(version) = versions::parse_from_output(&version_string) else {
91 return false;
92 };
93
94 debug!("Found {command} version: {version}");
95
96 versions::is_compatible(command, &version, &expected_version)
97}

Callers 1

ensure_binary_installedFunction · 0.85

Calls 3

parse_from_outputFunction · 0.85
is_compatibleFunction · 0.85
argMethod · 0.80

Tested by

no test coverage detected