Skip to content

Commit 60eb300

Browse files
committed
modwhich.rb: Fix for verbosity when used in conjunction with recursion.
1 parent 4080227 commit 60eb300

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

modwhich.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ def require(mod, verbose = verbose?)
6464
@load_order << mod
6565
current_paths = loaded_paths
6666

67-
ret = _modwhich_original_require(mod)
67+
ret = recursive_verbose(verbose) {
68+
_modwhich_original_require(mod)
69+
}
6870

6971
@added_paths.concat(loaded_paths - current_paths)
7072
@which[mod] = @added_paths.pop || gemwhich(mod)
@@ -87,6 +89,21 @@ def recursive?
8789
@recursive
8890
end
8991

92+
def recursive_verbose?(verbose)
93+
recursive? && !verbose.nil? && verbose != verbose?
94+
end
95+
96+
def recursive_verbose(verbose)
97+
recursive_verbose = recursive_verbose?(verbose)
98+
self.verbose = verbose if recursive_verbose
99+
100+
ret = yield
101+
102+
self.verbose = !verbose if recursive_verbose
103+
104+
ret
105+
end
106+
90107
def include?(mod)
91108
!to_a.assoc(mod).nil?
92109
end
@@ -156,16 +173,15 @@ def require(*args) ModWhich.require(*args) end
156173

157174
abort usage if help || ARGV.empty?
158175

159-
ModWhich.verbose = verbose
160176
ModWhich.init(ARGV, recursive)
161177

162-
ARGV.each { |mod| require mod }
178+
ARGV.each { |mod| require mod, verbose }
163179
else
164180
ModWhich.init
165181
end
166182

167183
at_exit {
168184
ModWhich.each { |mod, path|
169185
warn "require '#{mod}' => #{path || 'NOT FOUND'}"
170-
} unless ModWhich.verbose?
186+
} unless verbose || ModWhich.verbose?
171187
}

0 commit comments

Comments
 (0)