耙自定义参数对所有的任务? [英] Rake custom arguments for all tasks?

查看:121
本文介绍了耙自定义参数对所有的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个参数传递到耙独立运行我的任务。

I want to pass in an argument to rake independent of the task I run.

例如:

rake my_arg=foo
rake my_arg=foo :install
rake my_arg=foo :upgrade
rake my_arg=foo :bar

有没有办法做到这一点?

Is there a way to do this?

推荐答案

您可以在这样的发送参数:

You can send arguments in like this:

rake some_task arg1=value arg2=value

然后拉动命名参数了 ENV 您的rake任务里面的:

Then pull the named parameters out of ENV inside your rake task:

arg1 = ENV['arg1']
arg2 = ENV['arg2']

您还可以提供更多的传统的命令行开关是这样的:

You can also supply more traditional command line switches like this:

rake some_task -- --arg1=value --arg2=value

然后使用 OptionParser (或其他一些选项解析器)来解压缩 ARGV 。不要忘了额外的 - 如果你想使用交换机,将告诉来停止解析的命令行开关。

And then use OptionParser (or some other option parser) to unpack ARGV. Don't forget the extra -- if you want to use switches, that will tell rake to stop parsing the command line as switches.

这篇关于耙自定义参数对所有的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆