[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

rake - tasks with parameters

Its Me

12/19/2004 8:37:00 PM

I have a build that I could structure as a large number of tasks (not
file-based) with the following pattern:

task :a do
do stuff with <the target for :a> with <the params for :a>
end

task :b do
do stuff for <the target for :b> with <the params for :b>
end

I don't think rules are the right tool here for me. Would it make sense for
rake tasks to optionally take parameters:

task :a do |x, y, z|
do stuff with x y z
end

And would it make sense for rake to pick up x, y, z (and :a) from command
line parameters ?

If the dependency mechanism :a => [:b] had some way to know which of :a's
xyz params, if any, to pass on to :b, would this task-flow network with
parameters be useful more broadly?

Thanks!


1 Answer

Jim Weirich

12/20/2004 4:45:00 AM

0


itsme213 said:
> I have a build that I could structure as a large number of tasks (not
> file-based) with the following pattern:
>
> task :a do
> do stuff with <the target for :a> with <the params for :a>
> end
>
> task :b do
> do stuff for <the target for :b> with <the params for :b>
> end
>
> I don't think rules are the right tool here for me. Would it make sense
> for
> rake tasks to optionally take parameters:
>
> task :a do |x, y, z|
> do stuff with x y z
> end

When a task action is executed, it is passed the task that is currently
executing. for example

task :a do |t|
puts t.name # or other interesting stuff about the current task
end

> And would it make sense for rake to pick up x, y, z (and :a) from command
> line parameters ?

Parameters from the command line of the form name=value can be found in
the environment hash. For example, invoking rake like this ...

rake test TEST=name_of_test_file.rb

Means that you can find the name of the test with ...

task :test do
file = ENV['TEST']
# do something with 'file'
end

The command line args are put into the ENV hash so that you can specify
the value as either an environment variable or on the command line (and
the command line overrides any existing environment variable).

> If the dependency mechanism :a => [:b] had some way to know which of :a's
> xyz params, if any, to pass on to :b, would this task-flow network with
> parameters be useful more broadly?

I'm a little unclear on how this would work. Do you have a specific
example in mind?

--
-- Jim Weirich jim@weirichhouse.org http://onest...
-----------------------------------------------------------------
"Beware of bugs in the above code; I have only proved it correct,
not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)