如何使用非 rake 参数调用 rake [英] How to invoke rake with non-rake parameters

查看:58
本文介绍了如何使用非 rake 参数调用 rake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建图表的 rake 任务:

I have a rake task that creates diagrams:

task :diagram do
  `rake erd filetype=dot disconnected=true`
end

这个任务的执行速度很慢,我猜是因为在嵌套的 rake-invoke 语句中,整个 rails 环境被再次加载.

The execution of this task is quite slow and I guess it is because in the nested rake-invoke statement the whole rails environment is loaded again.

我想用 Rake::Task['...'].invoke 代替.但是 erd 任务有一些非 rake 参数(filetype=dot 等),它们似乎不适用于 invoke 方法.

I wanted to use Rake::Task['...'].invoke instead. But the erd task has some non-rake arguements (filetype=dot etc.), which don't seem to work with the invoke method.

有没有办法将这些参数传递给 rake,以便我可以使用正确的 rake 调用语法.

Is there a way to pass those arguments to rake so that I can use the proper rake invoke syntax.

推荐答案

尝试在代码中设置 ENV 变量:

Try setting the ENV variables in your code:

task :diagram do
  ENV['filetype']='dot'
  ENV['disconnected'='true'

  Rake::Task['erd'].invoke
end

这篇关于如何使用非 rake 参数调用 rake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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