Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake pass parameters to dependent tasks

Tags:

ruby

rake

Here is the current way I run rak dependent tasks

task :test => [:prepare_testdir,:run_tests]

currently there is no parameters for these two dependent tasks. But I need to add parameters to one of tasks. It should be running like on command line

rake prepare_testdir[mydir]

How do I pass this new parameter to this

task :test => [:prepare_testdir,:run_tests]

I have tried

task :test => [:prepare_testdir[mydir],:run_tests]

and

 task :test => [:prepare_testdir['mydir'],:run_tests]

both are not working.

Thanks in advance

like image 604
icn Avatar asked Sep 27 '12 00:09

icn


1 Answers

Inside the rake file

task :test, [:dir] => [:prepare_testdir] do |t,args|
  puts args.inspect # {:dir=>"foo"}
end

task :prepare_testdir, :dir do |t, args|
  puts args.inspect # {:dir=>"foo"}
end

Invocation

rake test[foo]
like image 59
peakxu Avatar answered Sep 18 '22 11:09

peakxu