diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-01-08 15:10:49 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-01-14 13:35:34 +0100 |
commit | 399cdf75fcdacfb4c68165a1bf401b12ecad1cb9 (patch) | |
tree | 75a5bbd9ae83c29014ce77905b2785726aef4c5b /src/util | |
parent | b6a52fd28003ed3ce251a3647e837ca11b9d1222 (diff) |
Move splitting of CLI env k-v-string to utility module
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/env.rs | 13 | ||||
-rw-r--r-- | src/util/mod.rs | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/util/env.rs b/src/util/env.rs new file mode 100644 index 0000000..e210b37 --- /dev/null +++ b/src/util/env.rs @@ -0,0 +1,13 @@ +use anyhow::Result; +use anyhow::anyhow; + +use crate::util::EnvironmentVariableName; + +pub fn parse_to_env(s: &str) -> Result<(EnvironmentVariableName, String)> { + let v = s.split("=").collect::<Vec<_>>(); + Ok(( + EnvironmentVariableName::from(*v.get(0).ok_or_else(|| anyhow!("Environment variable has no key: {}", s))?), + String::from(*v.get(1).ok_or_else(|| anyhow!("Environment variable has no key: {}", s))?) + )) +} + diff --git a/src/util/mod.rs b/src/util/mod.rs index 7077f47..539919a 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -29,6 +29,7 @@ impl AsRef<str> for EnvironmentVariableName { } pub mod docker; +pub mod env; pub mod filters; pub mod git; pub mod parser; |