Skip to content

Commit

Permalink
fix: spurious semver warning on mise outdated (#4199)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Jan 24, 2025
1 parent 47ad5d6 commit 637cd32
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/aqua/aqua_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ impl AquaRegistry {
.next()
.wrap_err(format!("no package found for {id} in {path:?}"))?;
if let Some(version_filter) = &pkg.version_filter {
// TODO: should this use AquaPackage::expr_parser somehow?
pkg.version_filter_expr = Some(Parser::new().compile(version_filter)?);
}
Ok(pkg)
Expand Down Expand Up @@ -248,24 +249,8 @@ impl AquaPackage {
}

fn version_override(&self, v: &str) -> &AquaPackage {
let ver = versions::Versioning::new(v.strip_prefix('v').unwrap_or(v));
let mut expr = Parser::new();
let expr = self.expr_parser(v);
let ctx = self.expr_ctx(v);
expr.add_function("semver", |c| {
if c.args.len() != 1 {
return Err("semver() takes exactly one argument".to_string().into());
}
let semver = c.args[0].as_string().unwrap().replace(' ', "");
if let Some(check_version) = versions::Requirement::new(&semver) {
if let Some(ver) = &ver {
Ok(check_version.matches(ver).into())
} else {
Err("invalid version".to_string().into())
}
} else {
Err("invalid semver".to_string().into())
}
});
vec![self]
.into_iter()
.chain(self.version_overrides.iter())
Expand Down Expand Up @@ -401,10 +386,31 @@ impl AquaPackage {
}

fn expr(&self, v: &str, program: Program) -> Result<Value> {
let expr = Parser::new();
let expr = self.expr_parser(v);
expr.run(program, &self.expr_ctx(v)).map_err(|e| eyre!(e))
}

fn expr_parser(&self, v: &str) -> Parser {
let ver = versions::Versioning::new(v.strip_prefix('v').unwrap_or(v));
let mut expr = Parser::new();
expr.add_function("semver", move |c| {
if c.args.len() != 1 {
return Err("semver() takes exactly one argument".to_string().into());
}
let semver = c.args[0].as_string().unwrap().replace(' ', "");
if let Some(check_version) = versions::Requirement::new(&semver) {
if let Some(ver) = &ver {
Ok(check_version.matches(ver).into())
} else {
Err("invalid version".to_string().into())
}
} else {
Err("invalid semver".to_string().into())
}
});
expr
}

fn expr_ctx(&self, v: &str) -> Context {
let mut ctx = Context::default();
ctx.insert("Version", v);
Expand Down

0 comments on commit 637cd32

Please sign in to comment.