WITH
task :commit => :c
you do not define an alias, you set the necessary condition. When you call :commit
, prerequsite :c
is called first. While there is only one prerequsite, and :commit
does not contain its own code, it may look like an alias, but it is not.
Knowing that you can "alias" your namespace if you define a default task for your namespace and set the necessary condition for this task (and a default condition for another namespace to be set again).
But I think there is no need for namespace aliases. It would be enough if you define a default job for the names of the names and possibly the "alias" of this task.
After reading the question again, I have an alternative idea based on Is there a method_missing method for rake tasks? :
require 'rake' namespace :long_namespace do task :a do |tsk| puts "inside #{tsk.name}" end end rule "" do |tsk| aliastask = tsk.name.sub(/short:/, 'long_namespace:') Rake.application[aliastask].invoke end Rake.application['short:a'].invoke
The rule defines the task_missing rule and tries to replace the namespace (in the example, it replaces "short" with "long_namespace").
Disadvantage: the undefined task does not return an error. So you need an adapted version:
require 'rake' namespace :long_namespace do task :a do |tsk| puts "inside #{tsk.name}" end end rule "" do |tsk| aliastask = tsk.name.sub(/short:/, 'long_namespace:') if Rake.application.tasks.map{|tsk| tsk.name }.include?( aliastask ) Rake.application[aliastask].invoke else raise RuntimeError, "Don't know how to build task '#{tsk.name}'" end end Rake.application['short:a'].invoke Rake.application['short:undefined'].invoke
And a more generalized version with the new aliasnamespace
method for defining alias namespaces:
require 'rake'
source share