Closed OnkelTem closed 5 years ago
I don't think there is an option type for that specific case. You can use the count option type multiple times, but it does not take a value.
You can use the map
or cast
option to achieve that though. Just pass in a function that will add the value to an array, and return the array of values.
You can use the map or cast option to achieve that though. Just pass in a function that will add the value to an array, and return the array of values.
Could you please provide an example? Because I tried map
(not cast
though) and it was called only once...
Wow. You are right. I totally missed that. I assumed it should work, but the tokens get deduped by array keys. Looks like it should be a fairly easy thing to fix though. I will look into putting up a PR soon.
See PR #93 or my branch accumulator-for-multiple-options-of-same-name 47135e1489a0b765f8269f17599c9bed117dcd4a
@NeoVance thanks man! I'll try it and write back
Oh forgot to include the info.
reduce (Closure $reducer)
Aliases: list
, each
, every
Execute an accumulator/reducer function on every instance of the option in the command. Takes an accumulator function, and returns mixed (you can return any value). If you also supply a map for the option the map will execute on every value before it is passed to the accumulator function.
Signature: function(mixed $accumulated, mixed $value) : mixed
$accumulated
: null|Option::default|mixed (the last value returned from the function, the option default value, or null.)$value
: mixed (the value that comes after the option. if map is supplied, the value returned from the map function.)return
: mixed (anything you want. The last value returned becomes the value of the Option after parsing.)Merged 93
I want to declare an option which could be invoked several times, e.g.:
This is similar to what
tar
have for files exclusion, .e.gI cannot find a way how to do this, or I'm missing something?