如何使用 rake 命令在命名空间的每个任务上运行函数
我想在命名空间中的每个 rake 任务上运行一个简单的函数 Enter_to_continue 。 目前我在每个任务的末尾添加该函数
,但是,这似乎是多余的,有没有办法通过进行一些元编程来运行这个函数,enter_to_continue,在命名空间“mytest”的每个任务的末尾自动运行?
namespace :mytest do
task :foo do
system "date"
enter_to_continue
end
task :bar do
system "ls"
enter_to_continue
end
# ...
# Let's say 10 more tasks ends with enter_to_continue comes after
# ...
end
def enter_to_continue
STDIN.gets.chomp
end
I want to run a simple function, enter_to_continue on every rake task in a namespace.
currently I add that function at the end of every single task
however, it seems redundant, is there any way to run this function, enter_to_continue, to run at the end of every task of namespace 'mytest' automatically, by doing some meta programming?
namespace :mytest do
task :foo do
system "date"
enter_to_continue
end
task :bar do
system "ls"
enter_to_continue
end
# ...
# Let's say 10 more tasks ends with enter_to_continue comes after
# ...
end
def enter_to_continue
STDIN.gets.chomp
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试 Rake::Task#enhance:
编辑:
您还可以在定义块内增强任务:
You could try Rake::Task#enhance:
Edit:
You may enhance the tasks also inside the definition block: