From 18c3ed43376a8b5e2d285d1b34a9f96843357d53 Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Sun, 17 Sep 2023 18:19:48 +0000 Subject: [PATCH] refactor: env handling target specific env's rather than looping through them all --- src/main.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 125a333..6b15751 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,21 +58,20 @@ fn setup_tracing() { /// An ENV is set in the ./containerised/Dockerfile, if this is ENV found, then sleep for 250ms, else the container, for as yet unknown reasons, will close immediately /// returns a bool, so that the `update_all_containers()` won't bother to check the entry point unless running via a container fn check_if_containerised() -> bool { - if std::env::vars().any(|x| x == (ENV_KEY.into(), ENV_VALUE.into())) { - std::thread::sleep(std::time::Duration::from_millis(250)); - true - } else { - false + if let Ok(value) = std::env::var(ENV_KEY) { + if value == ENV_VALUE { + std::thread::sleep(std::time::Duration::from_millis(250)); + return true; + } } + false } /// Read the optional docker_host path, the cli args take priority over the DOCKER_HOST env fn read_docker_host(args: &CliArgs) -> Option { args.host.as_ref().map_or_else( || { - std::env::vars() - .find(|x| x.0 == DOCKER_HOST) - .map(|(_, val)| val) + std::env::var(DOCKER_HOST).ok() }, |x| Some(x.to_string()), )