rake
rake copied to clipboard
Tasks that take arguments are only run for first set of arguments.
If you have a task that takes an argument, eg:
task "hi", [:name] do |t, args|
puts "hi #{args.name}"
end
and you want to run more than one invocation of the task with different arguments, eg:
rake hi[world] hi[there]
then only the first task is run, so in this case the output is:
$ rake hi[world] hi[there]
hi world
though my expected output would be
$ rake hi[world] hi[there]
hi world
hi there
when run with verbose the output is
rake -vt -f test.rakefile hi[world] hi[there]
** Invoke hi (first_time)
** Execute hi
hi world
** Invoke hi
which makes me think it's being filtered out as it thinks it's already been run.
This tripped me up as well :disappointed:
May be worth at least giving a warning to the user about "the task not being run a second time" when executing that command
I wonder maybe rake should run the task twice if invoked twice in the command line...
@hsbt Do you have any opinion about this?
Seems someone likes to use Rake as a shell script/batch replacement :)
But really: beginners which are not aware of all the internals of Rake will expect that both tasks will be executed because they look completely different and may have completely different behavior because of the parameter.
On the other hand: writing parameters in another format like foo --arg file1 --arg file2
shows that this expectation is very uncommon; I would not expect that foo
executes correctly in this case (I would expect "doublicate parameter error" or "use only last argument" or …)
I'm sure this is by design, and it's unlikely that we are going to change this since it's been there for many years and at this point there is probably a great number of tasks that indirectly depend on this behaviour. I don't fully understand the design decision here though.
As a workaround, re-enable the task at the end of the task you are trying to run multiple times in one go:
task :do_something do
# Do stuff
...
Rake::Task[:do_something].reenable
end
Fair enough :+1:
Good catch about reenable
.
I assume you would need to reenable the same you're defining though, right? I mean
-Rake::Task[:foo].reenable
+Rake::Task[:run].reenable
?
@grzuy my bad, I just updated my comment above.
:-) :+1: