Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,25 @@ pub(super) fn parse_u64_flag(flag: &str, value: &str) -> std::io::Result<u64> {
.map_err(|_| std::io::Error::other(format!("invalid value for {flag}: {value}")))
}

/// Expand `--flag=value` tokens into separate `--flag` and `value` tokens so
/// the hand-rolled subcommand parsers accept the same `--flag=value` form the
/// clap-generated help and completions imply. Only `value_options` are split:
/// boolean and unknown options keep their attached value so they still reach
/// the parser's unknown-option branch.
pub(super) fn expand_equals_args(args: &[String], value_options: &[&str]) -> Vec<String> {
let mut expanded = Vec::with_capacity(args.len());
for arg in args {
match arg.split_once('=') {
Some((flag, value)) if value_options.contains(&flag) => {
expanded.push(flag.to_string());
expanded.push(value.to_string());
}
_ => expanded.push(arg.clone()),
}
}
expanded
}

fn parse_session_json_only(args: &[String], usage: &str) -> Result<bool, i32> {
match args {
[] => Ok(false),
Expand Down Expand Up @@ -1121,4 +1140,29 @@ mod tests {
);
assert!(!super::server_not_running::was_reported(&mapped));
}

#[test]
fn expand_equals_args_splits_value_options_only() {
// Known value options split; values may contain `=`. Boolean and
// unknown options keep the attached form so parsers still reject them.
let args = vec![
"--match=a=b".to_string(),
"name=value".to_string(),
"--raw=value".to_string(),
"--bogus=value".to_string(),
"--timeout=5000".to_string(),
];
assert_eq!(
super::expand_equals_args(&args, &["--match", "--timeout"]),
vec![
"--match",
"a=b",
"name=value",
"--raw=value",
"--bogus=value",
"--timeout",
"5000",
]
);
}
}
Loading
Loading