Skip to content

Commit fdb8028

Browse files
committed
Merge pull request #393 from erikhuda/debug-config
Make possible to pass a debug config to the Base.start
2 parents e7838f7 + f25183e commit fdb8028

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

lib/thor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def create_command(meth) #:nodoc:
384384
@usage ||= nil
385385
@desc ||= nil
386386
@long_desc ||= nil
387-
387+
388388
if @usage && @desc
389389
base_class = @hide ? Thor::HiddenCommand : Thor::Command
390390
commands[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)

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`,

lib/thor/line_editor/readline.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def use_path_completion?
5050
class PathCompletion
5151
attr_reader :text
5252
private :text
53-
53+
5454
def initialize(text)
5555
@text = text
5656
end

spec/base_spec.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,22 @@ def hello
246246
describe '#start' do
247247
it 'raises an error instead of rescuing if THOR_DEBUG=1 is given' do
248248
begin
249-
ENV['THOR_DEBUG'] = 1
249+
ENV['THOR_DEBUG'] = '1'
250+
250251
expect do
251252
MyScript.start %w[what --debug]
252-
end.to raise_error(Thor::UndefinedcommandError, 'Could not find command "what" in "my_script" namespace.')
253-
rescue
253+
end.to raise_error(Thor::UndefinedCommandError, 'Could not find command "what" in "my_script" namespace.')
254+
ensure
254255
ENV['THOR_DEBUG'] = nil
255256
end
256257
end
257258

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+
258265
it 'does not steal args' do
259266
args = %w[foo bar --force true]
260267
MyScript.start(args)

0 commit comments

Comments
 (0)