2011-11-25 20 views
0
class B12 < Thor 
    desc "write", "write data into the index" 
    method_option :methods, :desc => "The methods to call on each RawData", :type => :array 
    def write(methods) 
    end 
end 

當我打電話通過雷神誤稱爲例外

thor b12:write --methods=foo 

文件,我得到

"write" was called incorrectly. Call as "thor b12:write". 

在哪裏的問題?

回答

0

你有幾件事情會在這裏引發問題。

首先,您使用的是methods,這是一個關於ruby的關鍵字。這將導致各種廢話。使用別的東西,比如my_methods

其次,您不需要通過my_methods寫入。這會創建一個默認選項,而不是一個命名選項。所以如果你想在這種情況下訪問my_methods,你可以撥打thor b12:write foo

這個工作,如果你把它叫做:thor b12:write --my_methods=foo

class B12 < Thor 
    desc "write", "write data into the index" 
    method_option :my_methods, :type => :array, :desc => "The methods to call on each RawData" 
    def write 
    puts options.my_methods 
    end 
end