I need to define a rake task that can handle any amount of arguments, pretty much like variadic functions in C++. But I could not find a way to define it within rake's DSL.
How can I create a rake task which can handle any amount of arguments? An example will be useful.
Thanks!
Rake as of version 0.8 cannot handle this, as mentioned in its documentation (it simply ignores any additional arguments).
However, if you can switch to using Thor, you can get this behavior. To demonstrate, create a Thorfile with this content:
class VariableArguments < Thor
desc 'multiple [ARGS]', "Task with multiple arguments"
def multiple(*args)
p args
end
end
and then call it like this:
$ thor variable_arguments:multiple one two three four five six
This prints the following:
["one", "two", "three", "four", "five", "six"]
(Tested using Thor 0.14.6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With