diff --git a/lib/thor/base.rb b/lib/thor/base.rb index 2e7fc6a64..2d3274a14 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -463,7 +463,10 @@ def namespace(name = nil) # def start(given_args = ARGV, config = {}) config[:shell] ||= Thor::Base.shell.new - dispatch(nil, given_args.dup, nil, config) + command_return = dispatch(nil, given_args.dup, nil, config) + + # Use the return value from the command to determine exit code + exit(1) unless command_return rescue Thor::Error => e config[:debug] || ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.message) exit(1) if exit_on_failure?