Pergunta

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

When I call the file via

thor b12:write --methods=foo

I get

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

Where's the problem?

Foi útil?

Solução

You've got a couple things going on here that'll cause issues.

First, you're using methods, which is a keyword in ruby. That's going to cause all sorts of nonsense. Use something else, like my_methods.

Second, you don't need to pass my_methods into write. That creates a default option, not a named option. So you'd call thor b12:write foo if you wanted access to my_methods in that context.

This works if you call it with: 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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top