Lots more updates
Also begin adding rust building capabilities to be able to write rust binaries for some commands.
This commit is contained in:
parent
624508dd14
commit
dd1cfa79e7
52 changed files with 2509 additions and 150 deletions
23
rust/lib/common/src/env.rs
Normal file
23
rust/lib/common/src/env.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Context;
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::json;
|
||||
|
||||
pub fn read_env(var: &'static str) -> anyhow::Result<String> {
|
||||
log::trace!("read_env: {var}");
|
||||
std::env::var(var)
|
||||
.map_err(|e| anyhow::format_err!("Could not read {var} environment variable: {e}"))
|
||||
}
|
||||
|
||||
pub fn read_path_env(var: &'static str) -> anyhow::Result<PathBuf> {
|
||||
Ok(read_env(var)?.into())
|
||||
}
|
||||
|
||||
pub fn read_env_json<T: for<'de> Deserialize<'de>>(var: &'static str) -> anyhow::Result<T> {
|
||||
let json_text = read_env(var)?;
|
||||
json::from_str(&json_text).with_context(|| {
|
||||
format!("Could not parse contents of env var {var} into the correct json format")
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue