Repository: starship/starship
File: src/modules/gradle.rs (Rust)

Code before:
        zipStoreBase=GRADLE_USER_HOME
        zipStorePath=wrapper/dists
    */
    let version = wrapper_properties
        .split_once("distributionUrl=")?
        .1
        .split_once("gradle-")?
        .1
        .split_once('-')?
        .0;
    Some(version.to_string())
}

/// Tries to find the gradle-wrapper.properties file.
fn find_wrapper_properties_file(directory: &Path, recursive: bool) -> Option<PathBuf> {
    let properties_path = directory.join("gradle/wrapper/gradle-wrapper.properties");
    if properties_path.exists() {
        return Some(properties_path);
    }

    if recursive {
        find_wrapper_properties_file(directory.parent()?, recursive)
    } else {
        None
    }
}

#[cfg(test)]
mod tests {
    use nu_ansi_term::Color;

    use super::*;
    use crate::test::ModuleRenderer;
    use std::fs::File;
    use std::io::{self, Write};

    #[test]
    fn folder_without_gradle_files() -> io::Result<()> {
        let dir = tempfile::tempdir()?;

        let actual = ModuleRenderer::new("gradle").path(dir.path()).collect();

        let expected = None;
        assert_eq!(expected, actual);
        dir.close()
    }

    #[test]
    fn folder_with_gradle_wrapper_properties() -> io::Result<()> {
        let dir = tempfile::tempdir()?;
        let properties = dir

Review comment (suggestion):
I would prefer this sort of thing, making use of the scanned directory contents and reading the file straight away:
```suggestion
fn get_wrapper_properties_file(context: &Context, recursive: bool) -> Option<String> {
    let mut properties = None;
    if context
        .try_begin_scan()?
        .set_folders(&["gradle"])
        .is_match()
    {
        properties =
            utils::read_file(&context.current_dir.join("gradle/wrapper/gradle-wrapper.properties")).ok();
    };

    if recursive && properties.is_none() {
        for dir in context.current_dir.ancestors().skip(1) {
            properties =
                utils::read_file(&dir.join("gradle/wrapper/gradle-wrapper.properties")).ok();
            if properties.is_some() {
                break;
            }
        }
    }

    properties
}
```

Code after:
        .rsplit_once('/')?
        .1
        .strip_prefix("gradle-")?
        .split_once('-')?
        .0;
    Some(version.to_string())
}

/// Tries to find the gradle-wrapper.properties file.
fn get_wrapper_properties_file(context: &Context, recursive: bool) -> Option<String> {
    let mut properties = None;
    if context
        .try_begin_scan()?
        .set_folders(&["gradle"])
        .is_match()
    {
        properties = utils::read_file(
            &context
                .current_dir
                .join("gradle/wrapper/gradle-wrapper.properties"),
        )
        .ok();
    };
    if recursive && properties.is_none() {
        for dir in context.current_dir.ancestors().skip(1) {
            properties =
                utils::read_file(&dir.join("gradle/wrapper/gradle-wrapper.properties")).ok();
            if properties.is_some() {
                break;
            }
        }
    }
    properties
}

#[cfg(test)]
mod tests {
    use nu_ansi_term::Color;

    use super::*;
    use crate::test::ModuleRenderer;
    use std::fs::{self, File};
    use std::io::{self, Write};

    #[test]
    fn folder_without_gradle_files() -> io::Result<()> {
        let dir = tempfile::tempdir()?;

        let actual = ModuleRenderer::new("gradle").path(dir.path()).collect();

        let expected = None;