refactor: env handling

target specific env's rather than looping through them all
This commit is contained in:
Jack Wills
2023-09-17 18:19:48 +00:00
parent b36daa5aea
commit 18c3ed4337
+7 -8
View File
@@ -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 /// 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 /// 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 { fn check_if_containerised() -> bool {
if std::env::vars().any(|x| x == (ENV_KEY.into(), ENV_VALUE.into())) { if let Ok(value) = std::env::var(ENV_KEY) {
std::thread::sleep(std::time::Duration::from_millis(250)); if value == ENV_VALUE {
true std::thread::sleep(std::time::Duration::from_millis(250));
} else { return true;
false }
} }
false
} }
/// Read the optional docker_host path, the cli args take priority over the DOCKER_HOST env /// Read the optional docker_host path, the cli args take priority over the DOCKER_HOST env
fn read_docker_host(args: &CliArgs) -> Option<String> { fn read_docker_host(args: &CliArgs) -> Option<String> {
args.host.as_ref().map_or_else( args.host.as_ref().map_or_else(
|| { || {
std::env::vars() std::env::var(DOCKER_HOST).ok()
.find(|x| x.0 == DOCKER_HOST)
.map(|(_, val)| val)
}, },
|x| Some(x.to_string()), |x| Some(x.to_string()),
) )