From 12afdf9d4ddad8e9838a881ce4527b1d14e700f1 Mon Sep 17 00:00:00 2001 From: TimJentzsch Date: Sat, 28 Sep 2024 14:41:02 +0200 Subject: [PATCH] Handle empty value lists for `ArgBuilder::add_value_list` (#116) Closes #115 --- src/external_cli/arg_builder.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/external_cli/arg_builder.rs b/src/external_cli/arg_builder.rs index a852ad0..da08ca4 100644 --- a/src/external_cli/arg_builder.rs +++ b/src/external_cli/arg_builder.rs @@ -98,7 +98,13 @@ impl ArgBuilder { V: Into, { let values: Vec = 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. @@ -196,6 +202,15 @@ mod tests { ); } + #[test] + fn add_value_list_empty_list_no_changes() { + let args = ArgBuilder::new().add_value_list("--features", Vec::::new()); + assert_eq!( + args.into_iter().collect::>(), + Vec::::new() + ); + } + #[test] fn append_adds_args_after_self() { let args = ArgBuilder::new()