wycats/thor — Issue #190: creating task alias automatically
Author: coolesting
Created: 2011-10-26 02:33:16+00:00
State: open

I have a method for showing the task name of alias and implementing the task alias.

class MyThor < Thor

desc "task_alias", "See the alias name of task"
def task_alias(output = true)
old_names = MyThor.instance_methods(false)
new_names = {}

i = 1;
old_names.each do |name|
key_name = ''
name.to_s.split('_').each do |subname| key_name << subname[0] end
begin
raise if new_names.has_key? key_name
new_names[key_name] = name
rescue
i++
j = i
key_name += j.to_s
retry
end
end

if output == true
new_names.each do |k,v| puts "#{v} => #{k}" end
else
#this line, it not works, cannot finds the method map
new_names.each do |k,v| map k => v.to_sym end
end
end

end

Question 1
How to implement this method task_alias(false) when the MyThor.start is invoked, i need to use this alias of task.

Question 2
How can i use the map method in a customize method, such as the task_alias