diff --git a/lib/thor/base.rb b/lib/thor/base.rb index c5f004e3e..1423955bc 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -644,6 +644,7 @@ def from_superclass(method, default = nil) # A flag that makes the process exit with status 1 if any error happens. def exit_on_failure? + Thor.deprecation_warning 'Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?`' false end diff --git a/spec/fixtures/command.thor b/spec/fixtures/command.thor index 26a02686b..20673036e 100644 --- a/spec/fixtures/command.thor +++ b/spec/fixtures/command.thor @@ -1,6 +1,10 @@ # module: random class Amazing < Thor + def self.exit_on_failure? + false + end + desc "describe NAME", "say that someone is amazing" method_options :forcefully => :boolean def describe(name, opts) diff --git a/spec/fixtures/script.thor b/spec/fixtures/script.thor index 6ea1c1e71..d83ad396e 100644 --- a/spec/fixtures/script.thor +++ b/spec/fixtures/script.thor @@ -1,6 +1,10 @@ class MyScript < Thor check_unknown_options! :except => :with_optional + def self.exit_on_failure? + false + end + attr_accessor :some_attribute attr_writer :another_attribute attr_reader :another_attribute @@ -200,6 +204,10 @@ module Scripts end class Arities < Thor + def self.exit_on_failure? + false + end + desc "zero_args", "takes zero args" def zero_args end diff --git a/spec/subcommand_spec.rb b/spec/subcommand_spec.rb index 42f173432..0546df4ae 100644 --- a/spec/subcommand_spec.rb +++ b/spec/subcommand_spec.rb @@ -55,6 +55,10 @@ def foo(name) class Parent < Thor desc "child1", "child1 description" subcommand "child1", Child1 + + def self.exit_on_failure? + false + end end end diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb index fd1e2a609..d97b7218e 100644 --- a/spec/thor_spec.rb +++ b/spec/thor_spec.rb @@ -173,6 +173,10 @@ def boring(*args) def exec(*args) [options, args] end + + def self.exit_on_failure? + false + end end it "passes remaining args to command when it encounters a non-option" do @@ -223,6 +227,10 @@ def exec(*args) def checked(*args) [options, args] end + + def self.exit_on_failure? + false + end end it "still accept options and arguments" do @@ -285,6 +293,10 @@ def exec(*args) def boring(*args) [options, args] end + + def self.exit_on_failure? + false + end end it "does not check the required option in the given command" do @@ -716,4 +728,19 @@ def unknown(*args) expect(MyScript.start(%w(send))).to eq(true) end end + + context "without an exit_on_failure? method" do + my_script = Class.new(Thor) do + desc "no arg", "do nothing" + def no_arg + end + end + + it "outputs a deprecation warning on error" do + expect do + my_script.start(%w[no_arg one]) + end.to output(/^Deprecation.*exit_on_failure/).to_stderr + end + end + end