Given something like:
namespace :my_tasks do
task :foo do
do_something
end
task :bar do
do_something_else
end
task :all => [:foo, :bar]
end
How do I make :all
be the default task, so that running rake my_tasks
will call it (instead of having to call rake my_tasks:all
)?
Place it outside the namespace like this:
Also... if your tasks require arguments then:
Notice how in the 2nd example you can call the task the same name as the namespace, ie 'my_tasks'
Add the following task outside of the namespace:
Keep in mind, that you can have a task with the same name as the namespace.
And hier a bigger example, that shows, how you can make use of tasks, which have the same name as the namespace, even when nesting namespaces:
Just copy it and try it out.
Not very intuitive, but you can have a namespace and a task that have the same name, and that effectively gives you what you want. For instance
Now you can run commands like,
and
The way I'm reading obvio171's question is that he is asking1) for a systematic way to invoke a certain task in a namespace by invoking the namespace as a task.
I've frequently encountered the same need. I like to logically group tasks into namespaces. Often that grouping resembles a hierarchy. Hence the desire to invoke the group makes very much sense to me.
Here's my take. Let me know what you think.
1)...or was asking, years ago. Nonetheless a still interesting question.
I suggest you to use this if you have lots of tasks in the namespace.
And then you can run all tasks in the namespace by:
With this, you don't need to worry to change your :all task when you add new tasks into that namespace.
I use this Rakefile for cucumber:
Then if I type just:
It runs the default task, which runs both fast and slow tests.
I learned this from Cheezy's blog.