bloomberg / stricli

Build complex CLIs with type safety and no dependencies
https://bloomberg.github.io/stricli
Apache License 2.0
630 stars 7 forks source link

fix: allow flags to parse arrays without variadic modifier #25

Open molisani opened 16 hours ago

molisani commented 16 hours ago

Resolves #21

Describe your changes Prior to this change, any flag type that extended from readonly (infer A)[] would be interpreted as a variadic parameter. The variadic modifier allows the flag to be specified multiple times, each input parsed separately, and the results returned as an array. However, this did not allow for the use case that a single parsed value (i.e. --flag=a,b,c) could produce an array as output (["a", "b", "c"]).

With this change, the variadic modifier can be dropped from flags with an array-based type and the parser will then expect that exact array-based type as output.

Testing performed Updated both formatting and scanner tests to confirm the new behavior.

Additional context This also allows for the possibility of accepting specific array-based types as flags, such as subclasses of TypedArray (types that are not only Array).