spin_common/arg_parser.rs
1//! Command line argument parsers
2
3use anyhow::bail;
4
5/// Parse an argument in the form `key=value` into a pair of strings.
6/// The error message is specific to key-value arguments.
7pub fn parse_kv(s: &str) -> anyhow::Result<(String, String)> {
8 parse_eq_pair(s, "Key/Values must be of the form `key=value`")
9}
10
11fn parse_eq_pair(s: &str, err_msg: &str) -> anyhow::Result<(String, String)> {
12 if let Some((key, value)) = s.split_once('=') {
13 Ok((key.to_owned(), value.to_owned()))
14 } else {
15 bail!("{err_msg}");
16 }
17}