Skip to content

Commit

Permalink
chore: rearrange env_utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Jul 20, 2024
1 parent f3aae1f commit 96ad483
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions crates/utils/src/env_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ pub fn get_env_var(key: &str) -> Result<String, VarError> {
std::env::var(key)
}

pub fn get_env_var_or_panic(key: &str) -> String {
get_env_var(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}

pub fn get_env_var_or_default(key: &str, default: &str) -> String {
get_env_var(key).unwrap_or(default.to_string())
}

pub fn get_env_var_optional(key: &str) -> Result<Option<String>, VarError> {
match get_env_var(key) {
Ok(s) => Ok(Some(s)),
Expand All @@ -14,12 +22,4 @@ pub fn get_env_var_optional(key: &str) -> Result<Option<String>, VarError> {

pub fn get_env_car_optional_or_panic(key: &str) -> Option<String> {
get_env_var_optional(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}

pub fn get_env_var_or_panic(key: &str) -> String {
get_env_var(key).unwrap_or_else(|e| panic!("Failed to get env var {}: {}", key, e))
}

pub fn get_env_var_or_default(key: &str, default: &str) -> String {
get_env_var(key).unwrap_or(default.to_string())
}
}

0 comments on commit 96ad483

Please sign in to comment.