Skip to content

Commit

Permalink
update kv_parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Ram committed May 27, 2024
1 parent 319733e commit 74a1aa7
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/utils/value_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ use anyhow::{anyhow, Result};

/// Parse key:value pair from string, used as a value_parser for Clap arguments
pub fn kv_parser(s: &str) -> Result<(String, String)> {
let pos = s
.find(':')
.ok_or_else(|| anyhow!(format!("`{s}` is missing a `:`")))?;
Ok((
s[..pos].parse().expect("infallible"),
s[pos + 1..].parse().expect("infallible"),
))
s.split_once(':')
.map(|(k, v)| (k.into(), v.into()))
.ok_or_else(|| anyhow!("`{s}` is missing a `:`"))
}

0 comments on commit 74a1aa7

Please sign in to comment.