Skip to content

Commit

Permalink
fix: Anchor CLI ignore non semver releases to avoid panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Arrowana committed Dec 17, 2024
1 parent 135d7e0 commit fe883ea
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,16 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC

let cfg = Config::discover(cfg_override)?;
if let Some(cfg) = cfg {
fn parse_version(text: &str) -> String {
Regex::new(r"(\d+\.\d+\.\S+)")
.unwrap()
.captures_iter(text)
.next()
.unwrap()
.get(0)
.unwrap()
.as_str()
.to_string()
fn parse_version(text: &str) -> Option<String> {
Some(
Regex::new(r"(\d+\.\d+\.\S+)")
.unwrap()
.captures_iter(text)
.next()?
.get(0)?
.as_str()
.to_string(),
)
}

fn get_current_version(cmd_name: &str) -> Result<String> {
Expand All @@ -577,7 +577,7 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
}

let output_version = std::str::from_utf8(&output.stdout)?;
let version = parse_version(output_version);
let version = parse_version(output_version).unwrap();
Ok(version)
}

Expand Down Expand Up @@ -633,9 +633,11 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC
}

// Hide the installation progress if the version is already installed
let is_installed = std::str::from_utf8(&output.stdout)?
.lines()
.any(|line| parse_version(line) == version);
let is_installed = std::str::from_utf8(&output.stdout)?.lines().any(|line| {
parse_version(line)
.map(|line_version| line_version == version)
.unwrap_or(false)
});
let (stderr, stdout) = if is_installed {
(Stdio::null(), Stdio::null())
} else {
Expand Down

0 comments on commit fe883ea

Please sign in to comment.