upend/cli/src/common.rs

36 lines
1.0 KiB
Rust
Raw Normal View History

use anyhow::{anyhow, Result};
2023-05-24 11:20:13 +02:00
use lazy_static::lazy_static;
use shadow_rs::is_debug;
pub fn get_static_dir<S: AsRef<str>>(dir: S) -> Result<std::path::PathBuf> {
let cwd = std::env::current_exe()?.parent().unwrap().to_path_buf();
let base_path = if is_debug() {
cwd.join("../../tmp/static")
} else {
cwd
};
let result = base_path.join(dir.as_ref());
if result.exists() {
Ok(result)
} else {
Err(anyhow!("Path {result:?} doesn't exist."))
}
}
2023-05-24 11:20:13 +02:00
lazy_static! {
static ref APP_USER_AGENT: String = format!(
"{} / {}",
upend::common::build::PROJECT_NAME,
upend::common::build::PKG_VERSION
);
pub static ref REQWEST_CLIENT: reqwest::blocking::Client = reqwest::blocking::Client::builder()
.user_agent(APP_USER_AGENT.as_str())
.build()
.unwrap();
pub static ref REQWEST_ASYNC_CLIENT: reqwest::Client = reqwest::Client::builder()
.user_agent(APP_USER_AGENT.as_str())
.build()
.unwrap();
2023-05-24 11:20:13 +02:00
}