开发者

How do you pass arguments to a rake task in RubyMine 3.0?

开发者 https://www.devze.com 2023-02-13 14:02 出处:网络
The situation I have a rake task similar to desc \"A rake Task\" task :give_me_gold, [:quantity,:quality] => :environment do |task, args|

The situation

I have a rake task similar to

desc "A rake Task"
task :give_me_gold, [:quantity,:quality] => :environment do |task, args|
 ....
end

I am aware from the commandline you type

rake give_me_gold[10,24] 

to pass parameters to the rake task. However when RubyMine runs the task it runs it like开发者_C百科 this:

rake give_me_gold[quantity,quality] --trace 10,24

Steps to reproduce

  1. Create a rake task that takes arguments.
  2. Have RubyMine installed version 3.0
  3. From RubyMine, click Tools -> Run Rake Task
  4. Input your rake task name. It should show up as "task[option,option]" and press enter
  5. A dialog will show up and ask for arguments. Fill it in and press enter
  6. Observe the command RubyMine runs.

Back to my question

How do you pass arguments to a rake task in RubyMine 3.0?

Thank you for taking the time to view this question


This is a bug in RubyMine. See Issue #8527 at jetbrains.net


task :give_me_gold do
  quantity = ENV['quantity']
  quality  = ENV['quality']
  puts "quantity: #{quantity}, quality: #{quality}"
end 

rake give_me_gold quantity=10 quality=24
#=> quantity: 10, quality: 24

upd

task :give_me_gold, :quantity, :quality do |t, args|
  puts "Args were: #{args}"
  quantity = args['quantity']
  quality  = args['quality']
  puts "quantity: #{quantity}, quality: #{quality}"
end

rake give_me_gold[10,24]
#=> quantity: 10, quality: 24


The good approach to pass inputs along with environment is:

**task :upload, [:path] => [:environment] do |t, args|

puts args
YOUR_MODEL.method(args)

end **

0

精彩评论

暂无评论...
验证码 换一张
取 消