How to pass command line arguments to a rake task

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

    I use a regular ruby argument in the rake file:

    DB = ARGV[1]
    

    then I stub out the rake tasks at the bottom of the file (since rake will look for a task based on that argument name).

    task :database_name1
    task :database_name2
    

    command line:

    rake mytask db_name
    

    this feels cleaner to me than the var=foo ENV var and the task args[blah, blah2] solutions.
    the stub is a little jenky, but not too bad if you just have a few environments that are a one-time setup

提交回复
热议问题