forked from keep-starknet-strange/snos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "utils" | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
license.workspace = true | ||
license-file.workspace = true | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::env::VarError; | ||
|
||
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) { | ||
// if value is empty string, return None | ||
Ok(s) if s.is_empty() => Ok(None), | ||
Ok(s) => Ok(Some(s)), | ||
Err(VarError::NotPresent) => Ok(None), | ||
Err(e) => Err(e), | ||
} | ||
} | ||
|
||
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)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod env_utils; |