[Rake-devel] Using new Rake arguments

Jim Weirich jim.weirich at gmail.com
Sun Dec 23 03:07:25 EST 2007

On Dec 22, 2007, at 11:41 PM, Adam Salter wrote:

> Dear all,
> I have seen that Rake has task arguments now. Sounds great and useful.
> How do I _actually_ use them? ;)

Heh ... sorry.  I need to write some docs.  But I didn't want to  
delay the new version for the write-up.

> Some examples would be good.
> e.g. ??
> rake upload[filename1, filename2]
> rake autoinstall[dir=abcd, options=123]

Close.  You have to obey the rules that the shell imposes.  So, either:

    rake upload[filename1,filename2]


    rake "upload[filename1, filename2]"

(the first has no spaces, the second quotes the arguments.  Rules  
vary on windows and non-ksh/bash shells).

> and how do I define these task arguments?

You have to tell the task the names of the arguments.  E.g.

    task :upload, :file1, :file2 do ... end

If you have dependencies, you use :needs ...

    task :upload, :file1, :file2, :needs => [:pre_upload] do ... end

To get to the args, the task lambdas get an extra argument ...

    task :upload, :file1, :file2 do |t, args|
      puts "File one is: #{args.file1}"
      puts "File two is: #{args.file2}"

Also, args[:file1] will work too.

> Just threw these together... probably completely off-base.

I'll get some official docs put together soon.  Thanks for your  

-- Jim Weirich
-- jim at weirichhouse.org

More information about the Rake-devel mailing list