0

因此,在我的 rake 命令中,当我执行 --trace 时,它​​只会在我手动执行的命令上执行,并且不会执行自定义 rake 执行的任何 rake 命令。

我的耙子命令:

namespace :db do
  task :regenesis do
    #because of how devestating this command could be, it's going 
    # to be forced to use the Test Environment
    puts "Re-Generating the Database"
    Rake::Task["db:drop RAILS_ENV=test --trace"].invoke
    Rake::Task["db:create RAILS_ENV=test"].invoke
    Rake::Task["db:create RAILS_ENV=test"].invoke
    Rake::Task["db:bootstrap RAILS_ENV=test"].invoke
  end
end

理想的情况是不必在其中硬编码 --trace =D

因此,我应该能够执行 rake db:regenesis --trace,并且它应该将跟踪附加到所有这些 rake 命令上。

我怎么做?

4

1 回答 1

1

请检查这个问题。如果您无法修改任务以添加参数(出于某种原因),则可以使用环境变量,例如:

namespace :db do
  task :regenesis do
    #because of how devestating this command could be, it's going 
    # to be forced to use the Test Environment
    puts "Re-Generating the Database"
    ENV["extra_option"] = "--trace"
    Rake::Task["db:drop RAILS_ENV=test"].invoke
    Rake::Task["db:create RAILS_ENV=test"].invoke
    Rake::Task["db:create RAILS_ENV=test"].invoke
    Rake::Task["db:bootstrap RAILS_ENV=test"].invoke
  end
end

在你的任务中你必须寻找ENV["extra_option"]

于 2011-09-01T19:30:51.437 回答