Merge branch 'master' into conditional-style

This commit is contained in:
Filip Bachul 2022-10-31 08:40:20 +01:00
commit 2295d92c1b
3 changed files with 25 additions and 6 deletions

View File

@ -23,7 +23,7 @@ license = "ISC"
readme = "README.md"
repository = "https://github.com/starship/starship"
# Note: MSRV is only intended as a hint, and only the latest version is officially supported in starship.
rust-version = "1.60"
rust-version = "1.64"
description = """
The minimal, blazing-fast, and infinitely customizable prompt for any shell! 🌌
"""

View File

@ -102,11 +102,19 @@ fn get_setup_cfg_version(context: &Context, config: &PackageConfig) -> Option<St
}
fn get_gradle_version(context: &Context, config: &PackageConfig) -> Option<String> {
let file_contents = context.read_file_from_pwd("build.gradle")?;
let re = Regex::new(r#"(?m)^version ['"](?P<version>[^'"]+)['"]$"#).unwrap();
let caps = re.captures(&file_contents)?;
context
.read_file_from_pwd("gradle.properties")
.and_then(|contents| {
let re = Regex::new(r"version=(?P<version>.*)").unwrap();
let caps = re.captures(&contents)?;
format_version(&caps["version"], config.version_format)
}).or_else(|| {
let build_file_contents = context.read_file_from_pwd("build.gradle")?;
let re = Regex::new(r#"(?m)^version ['"](?P<version>[^'"]+)['"]$"#).unwrap(); /*dark magic*/
let caps = re.captures(&build_file_contents)?;
format_version(&caps["version"], config.version_format)
format_version(&caps["version"], config.version_format)
})
}
fn get_composer_version(context: &Context, config: &PackageConfig) -> Option<String> {
@ -960,6 +968,17 @@ java {
expect_output(&project_dir, None, None);
project_dir.close()
}
#[test]
fn test_extract_grade_version_from_properties() -> io::Result<()> {
let config_name = "gradle.properties";
let config_content = "
version=1.2.3
";
let project_dir = create_project_dir()?;
fill_config(&project_dir, config_name, Some(config_content))?;
expect_output(&project_dir, Some("v1.2.3"), None);
project_dir.close()
}
#[test]
fn test_extract_mix_version() -> io::Result<()> {

View File

@ -136,7 +136,7 @@ impl<'de> Deserializer<'de> for ValueDeserializer<'de> {
.iter()
.filter_map(|field| {
let score = strsim::jaro_winkler(key, field);
(score > 0.8).then(|| (score, field))
(score > 0.8).then_some((score, field))
})
.max_by(|(score_a, _field_a), (score_b, _field_b)| {
score_a.partial_cmp(score_b).unwrap_or(Ordering::Equal)