Invoke rake task with arguments from another task
Asked Answered
H

2

25

I would like to be able to pass arguments for a task that I have to call from another task

Invoking without arguments works for me like this:

Rake::Task["mytask1"].invoke

However with arguments like this it does not:

Rake::Task["mytask1[1,v18_0,20141230]"].invoke

Thanks

Haematopoiesis answered 6/8, 2015 at 14:50 Comment(0)
R
59

you can try

Rake::Task[:my_task].invoke(1,'v18_0',20141230)

or you can do

Rake.application.invoke_task("my_task[1, 'v18_0', 20141230]")
Repulse answered 6/8, 2015 at 15:15 Comment(1)
Note you have to call .reenable to run the same task twice. See #22639694Linetta
F
8

You can pass in parameters through invoke

namespace :tester do
  desc "test"
  task :test, [:amount] => :environment do |task, args|
    puts "Your amount is #{args.amount}"
  end

  task :test_task do
    Rake::Task["tester:test"].invoke(100)
  end  
end

rake tester:test_task
Your amount is 100
Flotilla answered 6/8, 2015 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.