LoginSignup
4
4

More than 5 years have passed since last update.

thor で [WARNING] Attempted to create command "hoge" without usage or description.

Posted at

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

なおりました。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4