How to pass command line arguments to a rake task

后端 未结 19 2141
走了就别回头了
走了就别回头了 2020-11-22 10:13

I have a rake task that needs to insert a value into multiple databases.

I\'d like to pass this value into the rake task from the command line, or from another

19条回答
  •  [愿得一人]
    2020-11-22 10:38

    I couldn't figure out how to pass args and also the :environment until I worked this out:

    namespace :db do
      desc 'Export product data'
      task :export, [:file_token, :file_path] => :environment do |t, args|
        args.with_defaults(:file_token => "products", :file_path => "./lib/data/")
    
           #do stuff [...]
    
      end
    end
    

    And then I call like this:

    rake db:export['foo, /tmp/']
    

提交回复
热议问题