Skip to content

Commit

Permalink
Deprecate relying on default exit_on_failure? [rails#621]
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Oct 2, 2018
1 parent c7e38fd commit cc8e8fd
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/thor/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/command.thor
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/script.thor
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -180,6 +184,10 @@ module Scripts
class MyDefaults < Thor
check_unknown_options!

def self.exit_on_failure?
false
end

namespace :default
desc "cow", "prints 'moo'"
def cow
Expand All @@ -200,6 +208,10 @@ module Scripts
end

class Arities < Thor
def self.exit_on_failure?
false
end

desc "zero_args", "takes zero args"
def zero_args
end
Expand Down
4 changes: 4 additions & 0 deletions spec/subcommand_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions spec/thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit cc8e8fd

Please sign in to comment.