Skip to content

Commit 924b399

Browse files
committed
Fix another warning about $thor_runner
Previously `ruby -w`, when running an unknown command in Thor, a warning was printed: thor-1.0.1/lib/thor/base.rb:514: warning: global variable `$thor_runner' not initialized The global variable was being lazily defined in a method which is not the only entry point to Thor. This moves the global definition out to where the Thor class is defined.
1 parent 8ec6acb commit 924b399

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/thor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require_relative "thor/base"
33

44
class Thor
5+
$thor_runner ||= false
56
class << self
67
# Allows for custom "Command" package naming.
78
#
@@ -398,7 +399,6 @@ def dispatch(meth, given_args, given_opts, config) #:nodoc: # rubocop:disable Me
398399
# the namespace should be displayed as arguments.
399400
#
400401
def banner(command, namespace = nil, subcommand = false)
401-
$thor_runner ||= false
402402
command.formatted_usage(self, $thor_runner, subcommand).split("\n").map do |formatted_usage|
403403
"#{basename} #{formatted_usage}"
404404
end.join("\n")

spec/fixtures/verbose.thor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ $VERBOSE = true
55
require 'thor'
66

77
class Test < Thor
8+
def self.exit_on_failure?
9+
true
10+
end
811
end
912

1013
Test.start(ARGV)

spec/no_warnings_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77

88
expect(err).to be_empty
99
end
10+
11+
it "prints no warnings even when erroring" do
12+
root = File.expand_path("..", __dir__)
13+
_, err, = Open3.capture3("ruby -I #{root}/lib #{root}/spec/fixtures/verbose.thor noop")
14+
expect(err).to_not match(/warning:/)
15+
end
1016
end

0 commit comments

Comments
 (0)