Skip to content

Commit

Permalink
Handle empty value lists for ArgBuilder::add_value_list (#116)
Browse files Browse the repository at this point in the history
Closes #115
  • Loading branch information
TimJentzsch authored Sep 28, 2024
1 parent 1bc87ea commit 12afdf9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/external_cli/arg_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ impl ArgBuilder {
V: Into<String>,
{
let values: Vec<String> = value_list.into_iter().map(|val| val.into()).collect();
self.add_with_value(name, values.join(","))

// If there are no values to add, omit the name of the argument as well
if values.is_empty() {
self
} else {
self.add_with_value(name, values.join(","))
}
}

/// Add all arguments from the other builder to this one.
Expand Down Expand Up @@ -196,6 +202,15 @@ mod tests {
);
}

#[test]
fn add_value_list_empty_list_no_changes() {
let args = ArgBuilder::new().add_value_list("--features", Vec::<String>::new());
assert_eq!(
args.into_iter().collect::<Vec<String>>(),
Vec::<String>::new()
);
}

#[test]
fn append_adds_args_after_self() {
let args = ArgBuilder::new()
Expand Down

0 comments on commit 12afdf9

Please sign in to comment.