Skip to content

Commit 0c9b6e2

Browse files
committed
Deprecate relying on default exit_on_failure? [rails#621]
1 parent c15c5c6 commit 0c9b6e2

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
@@ -647,6 +647,7 @@ def from_superclass(method, default = nil)
647647

648648
# A flag that makes the process exit with status 1 if any error happens.
649649
def exit_on_failure?
650+
Thor.deprecation_warning 'Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?`'
650651
false
651652
end
652653

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
@@ -736,4 +748,19 @@ def unknown(*args)
736748
expect(MyScript.start(%w(send))).to eq(true)
737749
end
738750
end
751+
752+
context "without an exit_on_failure? method" do
753+
my_script = Class.new(Thor) do
754+
desc "no arg", "do nothing"
755+
def no_arg
756+
end
757+
end
758+
759+
it "outputs a deprecation warning on error" do
760+
expect do
761+
my_script.start(%w[no_arg one])
762+
end.to output(/^Deprecation.*exit_on_failure/).to_stderr
763+
end
764+
end
765+
739766
end

0 commit comments

Comments
 (0)