How can I pass named arguments to a Rake task?

别来无恙 提交于 2019-12-03 09:34:16

You can say things like this:

rake some_task -- --arg=value

And then, inside your task, ARGV will be

[ 'some_task', '--arg=value' ]

so you could use OptionParser (or some other option parser) to unpack ARGV just like in any old CLI script; the funny looking -- is necessary to keep rake from trying to parse --arg=like as a rake switch.

You're probably better off with the standard environment variable approach, it isn't as ugly as all the -- stuff and it is the usual way of passing arguments to rake tasks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!