Skip to content

Commit 33891c5

Browse files
committed
Deprecate relying on default exit_on_failure? [#621]
1 parent 57fe753 commit 33891c5

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed

lib/thor/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ def from_superclass(method, default = nil)
644644

645645
# A flag that makes the process exit with status 1 if any error happens.
646646
def exit_on_failure?
647+
Thor.deprecation_warning 'Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?`'
647648
false
648649
end
649650

spec/fixtures/command.thor

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# module: random
22

33
class Amazing < Thor
4+
def self.exit_on_failure?
5+
false
6+
end
7+
48
desc "describe NAME", "say that someone is amazing"
59
method_options :forcefully => :boolean
610
def describe(name, opts)

spec/fixtures/script.thor

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
class MyScript < Thor
22
check_unknown_options! :except => :with_optional
33

4+
def self.exit_on_failure?
5+
false
6+
end
7+
48
attr_accessor :some_attribute
59
attr_writer :another_attribute
610
attr_reader :another_attribute
@@ -200,6 +204,10 @@ module Scripts
200204
end
201205

202206
class Arities < Thor
207+
def self.exit_on_failure?
208+
false
209+
end
210+
203211
desc "zero_args", "takes zero args"
204212
def zero_args
205213
end

spec/subcommand_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def foo(name)
5555
class Parent < Thor
5656
desc "child1", "child1 description"
5757
subcommand "child1", Child1
58+
59+
def self.exit_on_failure?
60+
false
61+
end
5862
end
5963
end
6064

spec/thor_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ def boring(*args)
173173
def exec(*args)
174174
[options, args]
175175
end
176+
177+
def self.exit_on_failure?
178+
false
179+
end
176180
end
177181

178182
it "passes remaining args to command when it encounters a non-option" do
@@ -223,6 +227,10 @@ def exec(*args)
223227
def checked(*args)
224228
[options, args]
225229
end
230+
231+
def self.exit_on_failure?
232+
false
233+
end
226234
end
227235

228236
it "still accept options and arguments" do
@@ -285,6 +293,10 @@ def exec(*args)
285293
def boring(*args)
286294
[options, args]
287295
end
296+
297+
def self.exit_on_failure?
298+
false
299+
end
288300
end
289301

290302
it "does not check the required option in the given command" do
@@ -716,4 +728,19 @@ def unknown(*args)
716728
expect(MyScript.start(%w(send))).to eq(true)
717729
end
718730
end
731+
732+
context "without an exit_on_failure? method" do
733+
my_script = Class.new(Thor) do
734+
desc "no arg", "do nothing"
735+
def no_arg
736+
end
737+
end
738+
739+
it "outputs a deprecation warning on error" do
740+
expect do
741+
my_script.start(%w[no_arg one])
742+
end.to output(/^Deprecation.*exit_on_failure/).to_stderr
743+
end
744+
end
745+
719746
end

0 commit comments

Comments
 (0)