Gem 使用 Thor 的疑问

tzwm · May 04, 2014 · Last by zzz6519003 replied at June 15, 2023 · 2900 hits

我只是用 Thor 写个简单的 CLI,但用的时候发现 help 信息不知道为什么会有问题。 下面是我的代码:

require 'thor'

class Command < Thor
  desc "action1", "hahaha"
  def action1 
    puts "hahaha"
  end  

  desc "action2", "hehehe"
  def action2
    puts "hehehe"
  end  
end

Command.start
ruby tmp.rb help
Commands:
  tmp.rb action1         # hahaha
  tmp.rb action1         # hahaha
  tmp.rb action2         # hehehe
  tmp.rb action2         # hehehe
  tmp.rb help [COMMAND]  # Describe available commands or one specific c...

就像上面显示的这样,每个 action 都会显示两条重复的,不知道是哪里出错了。

顺便说下,我看了这个介绍OptionParser的 page,还是不知道怎么用optparse来做类似 git 这种有 action 的 CLI,所以只能用 Thor 来做了,虽然有点 overkill 了……

@tzwm 我测试下了,这貌似是 thor 的 bug, 建议将类名换一个名字:Command 改为 MyCLI 等。

#1 楼 @lyfi2003 呃,是的,我改了个类名就好了,谢谢……

You need to Sign in before reply, if you don't have an account, please Sign up first.