[Rake-devel] Passing Command Line Values to a Rakefile?

Charles F. I. Savage cfis at interserv.com
Sat Aug 20 02:49:55 EDT 2005

Is there a way to pass options to a Rakefile via the command-line? 

I'm automating setting up a Posgresql database for use with Rails.  The 
logic is create a database, add in plpgsql support, then add in the  
appropriate schemas.  So something like this:

# Create a database
task :create_database do |task|
       command = "createdb my_database"
     execute_command command

# Now install the plpgsql language
task :setup_plpgsql => :create_database do |task|
     command = "createlang  plpgsql"
     execute_command command

Now, let's say I want to do it for 3 separate databases.  One option is 
something like this:

DATABASES = %w[dev test production]

task :create_database do |task|
  DATABASES.each do |database|
        command = %{createdb  #{database}}
        execute_command command

However, I'd much rather be able to pass in the database name to the 
script.  Thus something like this from a shell script or other Ruby code:

rake -f MyRakefile --options="database=test"
rake -f MyRakefile --options="database=deploy"
rake -f MyRakefile --options="database=production"



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2781 bytes
Desc: S/MIME Cryptographic Signature
Url : http://rubyforge.org/pipermail/rake-devel/attachments/20050820/e86c5f28/smime-0001.bin

More information about the Rake-devel mailing list