Ruby Thor-方法中未识别命令行选项

Ruby Thor-方法中未识别命令行选项,ruby,thor,Ruby,Thor,我必须使用此命令来运行我的ruby程序: $ruby filename.rb NAME --from="People" --yell 我有这样的剧本: require 'thor' class CLI < Thor desc "hello NAME", "say hello to NAME" method_option :from, :required => true method_option :yell, :type => :boolean def s

我必须使用此命令来运行我的
ruby
程序:

$ruby filename.rb NAME --from="People" --yell
我有这样的剧本:

require 'thor'

class CLI < Thor
  desc "hello NAME", "say hello to NAME"

  method_option :from, :required => true
  method_option :yell, :type => :boolean
  def self.hello(name)
    output = []
    output << "from: #{options[:from]}" if options[:from]
    output << "Hello #{name}"
    output = output.join("\n")
    puts options[:yell] ? output.upcase : output
  end
end

CLI.hello(ARGV)
require'thor'
类CLItrue
方法_选项:yell,:type=>:boolean
def self.hello(姓名)
输出=[]
output ruby testing.rb Jay--from=“Ray”--yell
发件人:#
你好[“杰”,“--FROM=RAY”,“--YELL”]
它看起来像是
:无论我是否指定,yell
始终有效,
选项
hello
方法中都被解读为
名称
输入

require 'thor'

class CLI < Thor
  desc "hello NAME", "say hello to NAME"

  method_option :from, :required => true
  method_option :yell, :type => :boolean
  def hello(name)
    #do something
  end
end

CLI.start ARGV

我从在线教程中找到并尝试了许多方法,但问题没有解决。请告诉我出了什么问题。谢谢大家!

问题是由我在脚本中调用
CLI.hello ARGV
引起的。当程序运行时,它将调用
hello
方法,并将所有命令行输入识别为
hello
的参数,该参数是一个数组

解决此问题的方法之一是通过删除通过
start
方法调用脚本的
self
来公开
hello

require 'thor'

class CLI < Thor
  desc "hello NAME", "say hello to NAME"

  method_option :from, :required => true
  method_option :yell, :type => :boolean
  def hello(name)
    #do something
  end
end

CLI.start ARGV
require'thor'
类CLItrue
方法_选项:yell,:type=>:boolean
def你好(姓名)
#做点什么
结束
结束
CLI.start ARGV