File tree Expand file tree Collapse file tree 6 files changed +55
-0
lines changed Expand file tree Collapse file tree 6 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -344,6 +344,13 @@ def disable_required_check?(command) #:nodoc:
344
344
command && disable_required_check . include? ( command . name . to_sym )
345
345
end
346
346
347
+ def deprecation_warning ( message ) #:nodoc:
348
+ unless ENV [ 'THOR_SILENCE_DEPRECATION' ]
349
+ warn "Deprecation warning: #{ message } \n " +
350
+ 'You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.'
351
+ end
352
+ end
353
+
347
354
protected
348
355
349
356
def stop_on_unknown_option #:nodoc:
Original file line number Diff line number Diff line change @@ -645,6 +645,7 @@ def from_superclass(method, default = nil)
645
645
646
646
# A flag that makes the process exit with status 1 if any error happens.
647
647
def exit_on_failure?
648
+ Thor . deprecation_warning 'Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?`'
648
649
false
649
650
end
650
651
Original file line number Diff line number Diff line change 1
1
# module: random
2
2
3
3
class Amazing < Thor
4
+ def self . exit_on_failure?
5
+ false
6
+ end
7
+
4
8
desc "describe NAME" , "say that someone is amazing"
5
9
method_options :forcefully => :boolean
6
10
def describe ( name , opts )
Original file line number Diff line number Diff line change 1
1
class MyScript < Thor
2
2
check_unknown_options! :except => :with_optional
3
3
4
+ def self . exit_on_failure?
5
+ false
6
+ end
7
+
4
8
attr_accessor :some_attribute
5
9
attr_writer :another_attribute
6
10
attr_reader :another_attribute
@@ -186,6 +190,10 @@ module Scripts
186
190
class MyDefaults < Thor
187
191
check_unknown_options!
188
192
193
+ def self . exit_on_failure?
194
+ false
195
+ end
196
+
189
197
namespace :default
190
198
desc "cow" , "prints 'moo'"
191
199
def cow
@@ -206,6 +214,10 @@ module Scripts
206
214
end
207
215
208
216
class Arities < Thor
217
+ def self . exit_on_failure?
218
+ false
219
+ end
220
+
209
221
desc "zero_args" , "takes zero args"
210
222
def zero_args
211
223
end
Original file line number Diff line number Diff line change @@ -55,6 +55,10 @@ def foo(name)
55
55
class Parent < Thor
56
56
desc "child1" , "child1 description"
57
57
subcommand "child1" , Child1
58
+
59
+ def self . exit_on_failure?
60
+ false
61
+ end
58
62
end
59
63
end
60
64
Original file line number Diff line number Diff line change @@ -173,6 +173,10 @@ def boring(*args)
173
173
def exec ( *args )
174
174
[ options , args ]
175
175
end
176
+
177
+ def self . exit_on_failure?
178
+ false
179
+ end
176
180
end
177
181
178
182
it "passes remaining args to command when it encounters a non-option" do
@@ -223,6 +227,10 @@ def exec(*args)
223
227
def checked ( *args )
224
228
[ options , args ]
225
229
end
230
+
231
+ def self . exit_on_failure?
232
+ false
233
+ end
226
234
end
227
235
228
236
it "still accept options and arguments" do
@@ -285,6 +293,10 @@ def exec(*args)
285
293
def boring ( *args )
286
294
[ options , args ]
287
295
end
296
+
297
+ def self . exit_on_failure?
298
+ false
299
+ end
288
300
end
289
301
290
302
it "does not check the required option in the given command" do
@@ -732,4 +744,19 @@ def unknown(*args)
732
744
expect ( MyScript . start ( %w( send ) ) ) . to eq ( true )
733
745
end
734
746
end
747
+
748
+ context "without an exit_on_failure? method" do
749
+ my_script = Class . new ( Thor ) do
750
+ desc "no arg" , "do nothing"
751
+ def no_arg
752
+ end
753
+ end
754
+
755
+ it "outputs a deprecation warning on error" do
756
+ expect do
757
+ my_script . start ( %w[ no_arg one ] )
758
+ end . to output ( /^Deprecation.*exit_on_failure/ ) . to_stderr
759
+ end
760
+ end
761
+
735
762
end
You can’t perform that action at this time.
0 commit comments