Skip to content

Commit 72f2071

Browse files
author
Rafael Mendonça França
committed
Accept a debug config in the start method
This will make easier to start a debug environment per action.
1 parent ed0f1c1 commit 72f2071

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/thor/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def start(given_args = ARGV, config = {})
439439
config[:shell] ||= Thor::Base.shell.new
440440
dispatch(nil, given_args.dup, nil, config)
441441
rescue Thor::Error => e
442-
ENV['THOR_DEBUG'] == '1' ? (raise e) : config[:shell].error(e.message)
442+
config[:debug] || ENV['THOR_DEBUG'] == '1' ? (raise e) : config[:shell].error(e.message)
443443
exit(1) if exit_on_failure?
444444
rescue Errno::EPIPE
445445
# This happens if a thor command is piped to something like `head`,

spec/base_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,12 @@ def hello
256256
end
257257
end
258258

259+
it 'raises an error instead of rescuing if :debug option is given' do
260+
expect do
261+
MyScript.start %w[what], :debug => true
262+
end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
263+
end
264+
259265
it 'does not steal args' do
260266
args = %w[foo bar --force true]
261267
MyScript.start(args)

0 commit comments

Comments
 (0)