Skip to main content

get_available_version

Function get_available_version 

Source
pub fn get_available_version(name: &str) -> Option<String>
Expand description

What: Query the repositories for the latest available version of a package.

Inputs:

  • name: Package name looked up via pacman -Si.

Output:

  • Returns Some(String) with the version string advertised in the repositories.
  • Returns None on failure (package not found in repos or command error).

Details:

  • Strips revision suffixes (e.g., -1) so comparisons focus on the base semantic version.
  • Parses “Version: x.y.z” line from pacman -Si output.
  • Sets LC_ALL=C and LANG=C for consistent locale-independent output.
  • Gracefully degrades by returning None if pacman is unavailable or package not found.

§Example

use arch_toolkit::deps::get_available_version;

if let Some(version) = get_available_version("pacman") {
    println!("Available version: {}", version);
}