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 Sep 25, 2018
1 parent c15c5c6 commit 0c9b6e2
Show file tree
Hide file tree
Showing 5 changed files with 44 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 @@ -647,6 +647,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
8 changes: 8 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 @@ -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
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 @@ -736,4 +748,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 0c9b6e2

Please sign in to comment.