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

问题出在哪里?

4

1 回答 1

0

这里有几件事会导致问题。

首先,您使用methods的是 ruby​​ 中的关键字。这会引起各种胡说八道。使用其他东西,例如my_methods.

其次,你不需要传入my_methodswrite。这会创建一个默认选项,而不是命名选项。因此,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
于 2012-01-19T18:58:14.763 回答