From 22db631550ce18832b65f5c76a26a8b88ff958ef Mon Sep 17 00:00:00 2001 From: Jonathan LEI Date: Mon, 23 Sep 2024 00:28:58 +0800 Subject: [PATCH] feat: allow omitting compiler patch version Allows specifying Cairo version like `v2.7` or `2.7` instead of the full version. Using only the major version like `v2` is not supported as the Cairo compiler does not follow SemVer, and breaking changes are introduced between minor versions. --- src/compiler.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/compiler.rs b/src/compiler.rs index fb5e54d..36c91f2 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -147,8 +147,18 @@ impl ValueEnum for CompilerVersion { fn to_possible_value(&self) -> Option { match self { - Self::V2_6_4 => Some(PossibleValue::new("2.6.4").alias("v2.6.4")), - Self::V2_7_1 => Some(PossibleValue::new("2.7.1").alias("v2.7.1")), + Self::V2_6_4 => Some( + PossibleValue::new("2.6.4") + .alias("v2.6.4") + .alias("2.6") + .alias("v2.6"), + ), + Self::V2_7_1 => Some( + PossibleValue::new("2.7.1") + .alias("v2.7.1") + .alias("2.7") + .alias("v2.7"), + ), } } } @@ -158,8 +168,8 @@ impl FromStr for CompilerVersion { fn from_str(s: &str) -> Result { match s { - "2.6.4" | "v2.6.4" => Ok(Self::V2_6_4), - "2.7.1" | "v2.7.1" => Ok(Self::V2_7_1), + "2.6.4" | "v2.6.4" | "2.6" | "v2.6" => Ok(Self::V2_6_4), + "2.7.1" | "v2.7.1" | "2.7" | "v2.7" => Ok(Self::V2_7_1), _ => Err(anyhow::anyhow!("unknown version: {}", s)), } }