How to pass parameter to rake command, which is called using Rake :: Task

Here is my rake task

task :lab => :enviroment do 
  Rake::Task["db:rollback"].invoke('STEP=5')
end

It does not do what I want. I want to

rake db:rollback STEP=5

I am using Rails 3.2.1 on ruby ​​1.9.2.

On the command line, I want to execute

rake lab

The real case is much more complicated, but this is jist.

+5
source share
3 answers
task :lab => :enviroment do 
  ENV['STEP'] ||= 5
  Rake::Task["db:rollback"].invoke
end
+4
source

Parameters can be passed in a rake by specifying key / value pairs in the rake command:

rake options:show opt1=value1

These command line options are then automatically set as environment variables that can be accessed as part of your task:

namespace :options do

  desc "Show how to read in command line options"
  task :show do
    p "option1 is #{ENV['opt1']}"
  end

end
0
source

Passing this as an environment variable may be a better choice. Try:

task :lab => :enviroment do 
  Rake::Task["db:rollback"].invoke(ENV['STEP'])
end

rake db:rollback STEP=5
-1
source

All Articles