thorでバッチ処理用のファイルを作っていたら謎のエラー。
app.rb
require 'thor'
# コマンドの基本クラス
class App < Thor
desc 'hoge', 'puts Hoge'
desc 'fuga', 'puts Fuga'
def hoge
puts 'Hoge'
end
def fuga
puts 'Fuga'
end
end
App.start(ARGV)
実行
$ bundle exec ruby app.rb fuga
[WARNING] Attempted to create command "fuga" without usage or description. Call desc if you want this method to be available as command or declare it inside a no_commands{} block. Invoked from "hoge.rb:12:in `<class:App>'".
Could not find command "fuga".
fugaコマンドが見つからないエラー。
desc書いたのになんでだ? と思っていたら
descはメソッドの直前に書かないといけないらしい...
app.rb
require 'thor'
# コマンドの基本クラス
class App < Thor
desc 'hoge', 'puts Hoge'
def hoge
puts 'Hoge'
end
desc 'fuga', 'puts Fuga'
def fuga
puts 'Fuga'
end
end
App.start(ARGV)
$ bundle exec ruby app.rb fuga
Fuga
なおりました。