gpt4 book ai didi

ruby-on-rails - 我如何调用 Rake 中的另一个任务

转载 作者:数据小太阳 更新时间:2023-10-29 06:44:51 24 4
gpt4 key购买 nike

尽管这听起来可能与您在此处找到的其他问题相似,但还是有细微差别。我有两个目录,比如/home/rails/Rake 和/home/rails/test_app。 rails 目录是我放置所有 rails 项目的地方。

在 Rake 内部,我有一个 Rakefile 和一个 create.rake 文件。

这就是我的 rakefile 的样子

namespace :setup do 
desc "something"
task :init do
print "Name of the destination directory: "
name = STDIN.gets.strip
cp_r '.', "../#{name}/lib/tasks"
cd "../#{name}"
sh "rake setup:create"

end
end

create.rake

namespace :setup do 
desc "Install"
task :create do
sh 'git init'
#some other code
end
end

它的作用显而易见。我想将 Rake 目录的内容复制到/test_app/lib/tasks。然后将目录更改为 test_app 并运行 setup:create 定义在 install.rake 文件中的任务,该文件现在位于 test_app/lib/tasks 中。这行得通,但这是这样做的最佳方式吗?任何人都可以稍微提示一下它是如何完成的,即 Rake 方式。

这是我在使用 invoke 方法时得到的错误:

$ rake setup:init
Name of the destination directory:
testapp
cp -r . ../testapp/lib/tasks
cd ../testapp
rake aborted!
Don't know how to build task 'setup:create'
/home/TradeRaider/rails/Rake/Rakefile:8:in `block (2 levels) in <top (required)>'
/home/TradeRaider/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
/home/TradeRaider/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => setup:init
(See full trace by running task with --trace)

最佳答案

这更像 rake-ish :)

 Rake::Task["setup:create"].invoke

关于ruby-on-rails - 我如何调用 Rake 中的另一个任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17781608/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com