[Rake-devel] Suggestion: allow passing of extra command-line args to the task

Gavin Sinclair gsinclair at soyabean.com.au
Mon Jun 14 06:03:31 EDT 2004

Sometimes I want a Rake task to be able to accept command-line
arguments.  E.g., I'm generatin an HTML document from a Textile
input, but I might want to vary the input file on occasion.

I offer the following approach for discussion.

The Rakefile task would look something like this.

  desc "Generate HTML document."
  task :html do
    require 'generate'
    generate_document(ARGV[0] || DEFAULT_INPUT_FILE)

Rake is then called like this:

  $ rake html                 # default input, as usual

  $ rake html -- other.txt    # use specified input file

I like the fact that multiple arguments to 'rake' will result in
multiple tasks being executed.  Using '--' is a standard way to
indicate that no more arguments should be parsed.  Therefore, we can
have the normal Rake behaviour, plus we can have arguments being
passed to tasks.


More information about the Rake-devel mailing list