You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Through testing of the coerce option, I noticed that the coercion function is called for each element in the array instead of once for the entire array, regardless of the array option. This makes it impossible to coerce the array-as-a-whole within a coercion function.
Note that no context is lost with this approach because the coercion can always iterate over the array of values if it wishes to coerce them individually.
A possible alternative could be to pass the existing value (from argv) to the coerce function as a second parameter, to potentially allow coercion to "build up" or "reduce to" a desired value, but I think this could lead to a lot of confusion and would argue against it.
The text was updated successfully, but these errors were encountered:
Problem
Through testing of the
coerce
option, I noticed that the coercion function is called for each element in the array instead of once for the entire array, regardless of thearray
option. This makes it impossible to coerce the array-as-a-whole within a coercion function.Here's an example:
Proposal
Defer coercion (at least for arrays) until after initial parsing is done
This would allow the above example to work as is, with the following result:
Note that no context is lost with this approach because the coercion can always iterate over the array of values if it wishes to coerce them individually.
A possible alternative could be to pass the existing value (from
argv
) to the coerce function as a second parameter, to potentially allow coercion to "build up" or "reduce to" a desired value, but I think this could lead to a lot of confusion and would argue against it.The text was updated successfully, but these errors were encountered: