Rails: Pass Arguments To Rake Task

Pass Multiple Arguments

namespace :thing do
  desc "it does a thing"
  task :work, [:arg1, :arg2, :arg3] do |task, args|
    p args[:arg1]
    p args[:arg2]
    p args[:arg3]
  end
end

add environment

namespace :thing do
  desc "it does a thing"
  task :work, [:arg1, :arg2, :arg3] => :environment do |task, args|
    ...
  end
end
namespace :thing do
  desc "it does a thing"
  task :work, [:option, :foo, :bar] do |task, args|
    puts "work", args
  end

  task :another, [:option, :foo, :bar] do |task, args|
    puts "another #{args}"
    Rake::Task["thing:work"].invoke(args[:option], args[:foo], args[:bar])
    # or splat the args
    # Rake::Task["thing:work"].invoke(*args)
  end

end
rake thing:work[1,2,3]
=> work: {:option=>"1", :foo=>"2", :bar=>"3"}

rake thing:another[1,2,3]
=> another {:option=>"1", :foo=>"2", :bar=>"3"}
=> work: {:option=>"1", :foo=>"2", :bar=>"3"}

S1 S2 S3