summaryrefslogtreecommitdiffstats
path: root/src/util/env.rs
blob: b1c017015ed607454799d5e1b3c5d04a2d177913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::anyhow;
use anyhow::Result;

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))?,
        ),
    ))
}