Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ def compsys(to, name = File.basename($0)) # :nodoc:
end

def help_exit
if STDOUT.tty? && (pager = ENV.values_at(*%w[RUBY_PAGER PAGER]).find {|e| e && !e.empty?})
if $stdout.tty? && (pager = ENV.values_at(*%w[RUBY_PAGER PAGER]).find {|e| e && !e.empty?})
less = ENV["LESS"]
args = [{"LESS" => "#{!less || less.empty? ? '-' : less}Fe"}, pager, "w"]
print = proc do |f|
Expand All @@ -1060,7 +1060,7 @@ def help_exit
# pager terminated
end
if Process.respond_to?(:fork) and false
IO.popen("-") {|f| f ? Process.exec(*args, in: f) : print.call(STDOUT)}
IO.popen("-") {|f| f ? Process.exec(*args, in: f) : print.call($stdout)}
# unreachable
end
IO.popen(*args, &print)
Expand Down Expand Up @@ -1102,7 +1102,7 @@ def help_exit
#
Officious['*-completion-zsh'] = proc do |parser|
Switch::OptionalArgument.new do |arg|
parser.compsys(STDOUT, arg)
parser.compsys($stdout, arg)
exit
end
end
Expand Down
5 changes: 2 additions & 3 deletions test/optparse/test_optparse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ def test_help_pager
File.open(File.join(dir, "options.rb"), "w") do |f|
f.puts "#{<<~"begin;"}\n#{<<~'end;'}"
begin;
stdout = STDOUT.dup
stdout = $stdout.dup
def stdout.tty?; true; end
Object.__send__(:remove_const, :STDOUT)
STDOUT = stdout
$stdout = stdout
ARGV.options do |opt|
end;
100.times {|i| f.puts " opt.on('--opt-#{i}') {}"}
Expand Down