From 457edf925ac19d338a1c0976487f215263553fd2 Mon Sep 17 00:00:00 2001 From: tuhana Date: Tue, 2 Jul 2024 00:59:18 +0300 Subject: [PATCH] Fix issues with match and letter casings on `cli::list::VersionInputs`' `FromStr` implementation --- src/cli/list.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cli/list.rs b/src/cli/list.rs index d03ccd8..92e61b6 100644 --- a/src/cli/list.rs +++ b/src/cli/list.rs @@ -134,19 +134,17 @@ impl std::fmt::Display for VersionInputs { impl std::str::FromStr for VersionInputs { type Err = anyhow::Error; - fn from_str(str: &str) -> Result { - match str { + fn from_str(s: &str) -> Result { + let s = s.to_lowercase(); + + match s.as_str() { "all" => Ok(Self::All), "lts" => Ok(Self::Lts(None)), - _ if (str.starts_with('v') && str[2..].parse::().is_ok()) => { - Ok(Self::VersionString( - str.strip_prefix('v') - .map_or(str, |stripped_str| stripped_str) - .to_string(), - )) + _ if s.starts_with('v') && s[1..].parse::().is_ok() => { + Ok(Self::VersionString(s[1..].to_string())) } - _ if (str[1..].parse::().is_ok()) => Ok(Self::VersionString(str.to_string())), - _ => Ok(Self::Lts(Some(str.to_lowercase()))), + _ if (s.parse::().is_ok()) => Ok(Self::VersionString(s)), + _ => Ok(Self::Lts(Some(s))), } } }