How to pass command line arguments to a rake task

后端 未结 19 1961
走了就别回头了
走了就别回头了 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:59

    To run rake tasks with traditional arguments style:

    rake task arg1 arg2
    

    And then use:

    task :task do |_, args|
      puts "This is argument 1: #{args.first}"
    end
    

    Add following patch of rake gem:

    Rake::Application.class_eval do
    
      alias origin_top_level top_level
    
      def top_level
        @top_level_tasks = [top_level_tasks.join(' ')]
        origin_top_level
      end
    
      def parse_task_string(string) # :nodoc:
        parts = string.split ' '
        return parts.shift, parts
      end
    
    end
    
    Rake::Task.class_eval do
    
      def invoke(*args)
        invoke_with_call_chain(args, Rake::InvocationChain::EMPTY)
      end
    
    end
    
    0 讨论(0)
提交回复
热议问题