如何在 Rake 中将参数从父任务传递到子任务?
我正在编写一个 Rake 脚本,其中包含带有参数的任务。我弄清楚了如何传递参数以及如何使任务依赖于其他任务。
task :parent, [:parent_argument1, :parent_argument2, :parent_argument3] => [:child1, :child2] do
# Perform Parent Task Functionalities
end
task :child1, [:child1_argument1, :child1_argument2] do |t, args|
# Perform Child1 Task Functionalities
end
task :child2, [:child2_argument1, :child2_argument2] do |t, args|
# Perform Child2 Task Functionalities
end
- 我可以将参数从父任务传递给子任务吗?
- 有没有办法让子任务成为私有任务,这样它们就不能被独立调用?
I am writing a Rake script which consists of tasks with arguments. I figured out how to pass arguments and how to make a task dependent on other tasks.
task :parent, [:parent_argument1, :parent_argument2, :parent_argument3] => [:child1, :child2] do
# Perform Parent Task Functionalities
end
task :child1, [:child1_argument1, :child1_argument2] do |t, args|
# Perform Child1 Task Functionalities
end
task :child2, [:child2_argument1, :child2_argument2] do |t, args|
# Perform Child2 Task Functionalities
end
- Can I pass the arguments from the parent task to the child tasks?
- Is there a way to make the child tasks as private so they can't be called independently?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我实际上可以想到三种在 Rake 任务之间传递参数的方法。
使用 Rake 的内置参数支持:
通过
Rake::Task#invoke
:另一个解决方案是猴子补丁 Rake 的主要应用程序对象 Rake::应用程序
并用它来存储任意值:
I can actually think of three ways for passing arguments between Rake tasks.
Use Rake’s built-in support for arguments:
Directly invoke tasks via
Rake::Task#invoke
:Another solution would be to monkey patch Rake’s main application object Rake::Application
and use it to store arbitary values:
设置属性似乎也很有魅力。
只需确保将任务依赖项设置为设置您需要的属性的任务即可。
Setting attributes seems to work like a charm too.
Just ensure the the task dependency is set to the task that sets the attributes you need.