1

I would to know if it was possible to pass an option from the commande line to the task without having the Rakefile taking option for itself.

Here is my task:

task :task do
 args = ARGV.drop(1)
 system("ruby test/batch_of_test.rb #{args.join(' ')}")
 args.each { |arg| task arg.to_sym do ; end }
end

Here is the command I want to be functional:

rake task --name test_first_one

The result I want is the same as this:

ruby test/batch_of_test.rb --name test_first_one

For this code, I get this error:

invalid option: --name

How can --name (or another option) can be passed to my task ?

Elie Teyssedou
  • 749
  • 1
  • 7
  • 19
  • 1
    Possible duplicate of [How do I pass command line arguments to a rake task?](http://stackoverflow.com/questions/825748/how-do-i-pass-command-line-arguments-to-a-rake-task) – Robin Nov 24 '15 at 11:43
  • No, I read it at least two times. My problem is related to passing options and not exactly arguments... (with "--" or '-' ). – Elie Teyssedou Nov 24 '15 at 11:51

2 Answers2

2

As far as I know you cannot add flags to Rake tasks. I think the closest syntax available is using ENV variables.

rake task NAME=test_first_one

Then in your task:

name = ENV['NAME']
Charlie Egan
  • 4,878
  • 6
  • 33
  • 48
1

like this:

task :task, [args] => :environment do |t, args|
 system("ruby test/batch_of_test.rb #{args.join(' ')}")
 args.each { |arg| task arg.to_sym do ; end }
end

and you call it like this.

rake task[args]

UPDATE

task :task, [:options] => :environment do |t, args|
 arg = args[:options].pop
 options = args[:options] 
end
bosskovic
  • 2,034
  • 1
  • 14
  • 29