LoginSignup
2
0

More than 5 years have passed since last update.

Thorで終了ステータス 1 で終了するための exit_on_failure とその現状

Posted at

RubyのCLIの開発を支援するライブラリである thor は
デフォルトで引数不足などの異常終了時に status 0 を返却します。

これは thor の exit_on_failure メソッドが false を固定で返却していることによります。
そのため、このメソッドを true でオーバーライドすることによって 1 を返却するように
変更することができます。

class HogeCommand < Thor
  class << self
    def exit_on_failure?
      true
    end
  end

  desc 'hoge', 'hoge command'
  def hoge
    puts "hoge"
  end
end

Thor 本体の Issue

Thor の Issue でこの問題は起票済みで、2017/01/13現在未修正であるようです。

Ok, so we bump the major version of Thor, and put it in the changelog. That's what semantic versioning is for, right?

メジャーバージョンアップで修正されるとのことなので version 1 になったら修正されるのかな?
(現在は version 0.19.4)

Returns exit 0 when a required argument is not provided - issue 244 - erikhuda/thor - GitHub

外部資料

2
0
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
2
0