Parse() dos not capture multiple values for repeated arguments
jpdillingham opened this issue · comments
Per the documentation, this is supposed to work, but it doesn't.
Here's a failing test:
[Fact]
public void ParseMultiples()
{
Dictionary<string, object> test = Arguments.Parse("--test 1 --test 2").ArgumentDictionary;
Assert.NotEmpty(test);
Assert.Single(test);
Assert.Equal("1,2", test["test"]);
}
This is working as expected when you consider this line. It needs to be changed to append additional values if the key is already present.
I'll have to think about whether this will cause any breaking changes.
This won't work unless a target Type
is supplied to Parse()
that has top-level properties that match the argument. I need this to work for a complex target type and/or without a type at all.
Changing the existing behavior to append values instead of replace them would be a breaking change, so I'll look at adding a parameter to Parse()
, like appendRepeatedValuesForUnmatchedArguments
. This is a rather verbose name, but it is warranted in this case because the behavior being changed is very specific.
The existing behavior matches the argument to a property on the target type, and uses the backing type of the property to determine whether to append or replace values (through IsCollection
, which matches Array
and List<T>
). In the absence of a matching property, AddOrUpdate
is used.