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

Code before:
            let json = utils::read_file(docker_config).ok()?;
            let parsed_json: serde_json::Value = serde_json::from_str(&json).ok()?;
            parsed_json.get("currentContext")?.as_str()?.to_owned()
        }
    };

    if ctx == "default" {
        return None;
    }

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_meta(|variable, _| match variable {
                "symbol" => Some(config.symbol),
                _ => None,
            })
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "context" => Some(Ok(if ctx.contains("unix://") {
                    ""
                } else {
                    ctx.as_str()
                })),
                _ => None,
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `docker_context`:\n{}", error);
            return None;
        }
    });
    Some(module)
}

#[cfg(test)]
mod tests {
    use crate::test::ModuleRenderer;
    use nu_ansi_term::Color;
    use std::fs::File;
    use std::io::{self, Write};

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

Review comment (suggestion):
I would prefer handling it like this:
```suggestion
                "context" if !ctx.starts_with("unix://") => Some(Ok(ctx.as_str())),
```

Code after:
            let json = utils::read_file(docker_config).ok()?;
            let parsed_json: serde_json::Value = serde_json::from_str(&json).ok()?;
            parsed_json.get("currentContext")?.as_str()?.to_owned()
        }
    };

    if ctx == "default" || ctx.starts_with("unix://") {
        return None;
    }

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_meta(|variable, _| match variable {
                "symbol" => Some(config.symbol),
                _ => None,
            })
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "context" => Some(Ok(ctx.as_str())),
                _ => None,
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `docker_context`:\n{}", error);
            return None;
        }
    });
    Some(module)
}

#[cfg(test)]
mod tests {
    use crate::test::ModuleRenderer;
    use nu_ansi_term::Color;
    use std::fs::File;
    use std::io::{self, Write};

    #[test]
    fn only_trigger_when_docker_config_exists() -> io::Result<()> {
        let cfg_dir = tempfile::tempdir()?;
        let actual = ModuleRenderer::new("docker_context")
            .env("DOCKER_CONFIG", cfg_dir.path().to_string_lossy())
            .collect();
        let expected = None;