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".问题出在哪里?
发布于 2012-01-20 02:58:15
这里有几件事会引起问题。
首先,您使用的是methods,这是ruby中的一个关键字。这会导致各种各样的胡言乱语。使用其他东西,比如my_methods。
其次,您不需要将my_methods传递给write。这会创建默认选项,而不是命名选项。因此,如果您希望在该上下文中访问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
endhttps://stackoverflow.com/questions/8267646
复制相似问题