From: Jim Weirich Date: 2004-12-20T13:44:34+09:00 Subject: Re: rake - tasks with parameters 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 with > end > > task :b do > do stuff for with > 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://onestepback.org ----------------------------------------------------------------- "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)