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
40
rust/lib/common/src/lib.rs
Normal file
40
rust/lib/common/src/lib.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use log::LevelFilter;
|
||||
|
||||
pub mod base64;
|
||||
pub mod bitwarden;
|
||||
pub mod curl;
|
||||
pub mod env;
|
||||
pub mod fs;
|
||||
pub mod json;
|
||||
pub mod proc;
|
||||
pub mod yaml;
|
||||
|
||||
pub fn read_level_filter() -> LevelFilter {
|
||||
let env = env::read_env("LOGLEVEL").unwrap_or(String::from("INFO"));
|
||||
let env_upper = env.to_uppercase();
|
||||
let level = match env_upper.as_str() {
|
||||
"VERBOSE" => "TRACE",
|
||||
"WARNING" => "WARN",
|
||||
l => l,
|
||||
};
|
||||
log::LevelFilter::from_str(level).unwrap_or(log::LevelFilter::Info)
|
||||
}
|
||||
|
||||
pub fn entrypoint(m: impl FnOnce() -> anyhow::Result<()>) {
|
||||
env_logger::builder()
|
||||
.filter_level(read_level_filter())
|
||||
.format_timestamp(None)
|
||||
.format_module_path(false)
|
||||
.format_file(false)
|
||||
.format_source_path(false)
|
||||
.format_target(false)
|
||||
.try_init()
|
||||
.expect("Could not set logger");
|
||||
let res = m();
|
||||
if let Err(err) = res {
|
||||
log::error!("{err:#}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue