thor错误地称为异常

时间:2011-11-25 10:25:07

标签: ruby thor invocation

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".

问题出在哪里?

1 个答案:

答案 0 :(得分:0)

你在这里发生了一些事情会导致问题。

首先,您使用的是methods,这是ruby中的关键字。那会引起各种各样的废话。使用其他内容,例如my_methods

其次,您不需要将my_methods传递给写入。这会创建一个默认选项,而不是命名选项。因此,如果您希望在该上下文中访问thor b12:write foo,则可以致电my_methods

如果您使用: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