Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate relying on default exit_on_failure? #625

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ def disable_required_check?(command) #:nodoc:
command && disable_required_check.include?(command.name.to_sym)
end

def deprecation_warning(message) #:nodoc:
unless ENV['THOR_SILENCE_DEPRECATION']
warn "Deprecation warning: #{message}\n" +
'You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.'
end
end

protected

def stop_on_unknown_option #:nodoc:
Expand Down
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