mirror of
https://github.com/starship/starship.git
synced 2024-11-07 08:54:50 +01:00
fix(docker_context): Ignore Docker Desktop "desktop-linux" context. (#6314)
* Docker Desktop uses "desktop-linux" instead of "default" as the default context since version 3.5. This filters "desktop-linux" in the same way as "default". https://github.com/starship/starship/issues/6170 * update docs/config/README.md
This commit is contained in:
parent
77f08832d5
commit
14babde435
@ -1267,7 +1267,7 @@ disabled = false
|
|||||||
|
|
||||||
The `docker_context` module shows the currently active
|
The `docker_context` module shows the currently active
|
||||||
[Docker context](https://docs.docker.com/engine/context/working-with-contexts/)
|
[Docker context](https://docs.docker.com/engine/context/working-with-contexts/)
|
||||||
if it's not set to `default` or if the `DOCKER_MACHINE_NAME`, `DOCKER_HOST` or
|
if it's not set to `default` or `desktop-linux`, or if the `DOCKER_MACHINE_NAME`, `DOCKER_HOST` or
|
||||||
`DOCKER_CONTEXT` environment variables are set (as they are meant to override
|
`DOCKER_CONTEXT` environment variables are set (as they are meant to override
|
||||||
the context in use).
|
the context in use).
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ use crate::utils;
|
|||||||
/// - Or there is a file named `$HOME/.docker/config.json`
|
/// - Or there is a file named `$HOME/.docker/config.json`
|
||||||
/// - Or a file named `$DOCKER_CONFIG/config.json`
|
/// - Or a file named `$DOCKER_CONFIG/config.json`
|
||||||
/// - The file is JSON and contains a field named `currentContext`
|
/// - The file is JSON and contains a field named `currentContext`
|
||||||
/// - The value of `currentContext` is not `default`
|
/// - The value of `currentContext` is not `default` or `desktop-linux`
|
||||||
/// - If multiple criteria are met, we use the following order to define the docker context:
|
/// - If multiple criteria are met, we use the following order to define the docker context:
|
||||||
/// - `DOCKER_HOST`, `DOCKER_CONTEXT`, $HOME/.docker/config.json, $`DOCKER_CONFIG/config.json`
|
/// - `DOCKER_HOST`, `DOCKER_CONTEXT`, $HOME/.docker/config.json, $`DOCKER_CONFIG/config.json`
|
||||||
/// - (This is the same order docker follows, as `DOCKER_HOST` and `DOCKER_CONTEXT` override the
|
/// - (This is the same order docker follows, as `DOCKER_HOST` and `DOCKER_CONTEXT` override the
|
||||||
@ -57,7 +57,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if ctx == "default" || ctx.starts_with("unix://") {
|
let default_contexts = ["default", "desktop-linux"];
|
||||||
|
if default_contexts.contains(&ctx.as_str()) || ctx.starts_with("unix://") {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,6 +348,24 @@ mod tests {
|
|||||||
cfg_dir.close()
|
cfg_dir.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_docker_context_default_after_3_5() -> io::Result<()> {
|
||||||
|
let cfg_dir = tempfile::tempdir()?;
|
||||||
|
|
||||||
|
let actual = ModuleRenderer::new("docker_context")
|
||||||
|
.env("DOCKER_CONTEXT", "desktop-linux")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[docker_context]
|
||||||
|
only_with_files = false
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let expected = None;
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
cfg_dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_docker_context_overrides_config() -> io::Result<()> {
|
fn test_docker_context_overrides_config() -> io::Result<()> {
|
||||||
let cfg_dir = tempfile::tempdir()?;
|
let cfg_dir = tempfile::tempdir()?;
|
||||||
|
Loading…
Reference in New Issue
Block a user