зеркало из https://github.com/github/ruby.git
open3.rb don't use keyword splat (**).
revert r43582, r49173 and r49177. open3 arguments uses spawn-like keyword arguments. Both symbol and integer keys are used. ``` Open3.capture2(*command, :in => IO::NULL, 3 => IO::NULL) `` This style cannot be supported with keyword splat (**) since Ruby 2.6. Because Ruby 2.6 prohibits symbol/non-symbol key hash separation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66352 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
914a290324
Коммит
c8cb0565a1
101
lib/open3.rb
101
lib/open3.rb
|
@ -81,7 +81,13 @@ module Open3
|
|||
# If merged stdout and stderr output is not a problem, you can use Open3.popen2e.
|
||||
# If you really need stdout and stderr output as separate strings, you can consider Open3.capture3.
|
||||
#
|
||||
def popen3(*cmd, **opts, &block)
|
||||
def popen3(*cmd, &block)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
in_r, in_w = IO.pipe
|
||||
opts[:in] = in_r
|
||||
in_w.sync = true
|
||||
|
@ -136,7 +142,13 @@ module Open3
|
|||
# p o.read #=> "*"
|
||||
# }
|
||||
#
|
||||
def popen2(*cmd, **opts, &block)
|
||||
def popen2(*cmd, &block)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
in_r, in_w = IO.pipe
|
||||
opts[:in] = in_r
|
||||
in_w.sync = true
|
||||
|
@ -179,7 +191,13 @@ module Open3
|
|||
# }
|
||||
# }
|
||||
#
|
||||
def popen2e(*cmd, **opts, &block)
|
||||
def popen2e(*cmd, &block)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
in_r, in_w = IO.pipe
|
||||
opts[:in] = in_r
|
||||
in_w.sync = true
|
||||
|
@ -192,10 +210,6 @@ module Open3
|
|||
module_function :popen2e
|
||||
|
||||
def popen_run(cmd, opts, child_io, parent_io) # :nodoc:
|
||||
if last = Hash.try_convert(cmd.last)
|
||||
opts = opts.merge(last)
|
||||
cmd.pop
|
||||
end
|
||||
pid = spawn(*cmd, opts)
|
||||
wait_thr = Process.detach(pid)
|
||||
child_io.each(&:close)
|
||||
|
@ -254,7 +268,16 @@ module Open3
|
|||
# STDOUT.binmode; print thumbnail
|
||||
# end
|
||||
#
|
||||
def capture3(*cmd, stdin_data: '', binmode: false, **opts)
|
||||
def capture3(*cmd)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
stdin_data = opts.delete(:stdin_data) || ''
|
||||
binmode = opts.delete(:binmode)
|
||||
|
||||
popen3(*cmd, opts) {|i, o, e, t|
|
||||
if binmode
|
||||
i.binmode
|
||||
|
@ -306,7 +329,16 @@ module Open3
|
|||
# End
|
||||
# image, s = Open3.capture2("gnuplot", :stdin_data=>gnuplot_commands, :binmode=>true)
|
||||
#
|
||||
def capture2(*cmd, stdin_data: nil, binmode: false, **opts)
|
||||
def capture2(*cmd)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
stdin_data = opts.delete(:stdin_data)
|
||||
binmode = opts.delete(:binmode)
|
||||
|
||||
popen2(*cmd, opts) {|i, o, t|
|
||||
if binmode
|
||||
i.binmode
|
||||
|
@ -345,7 +377,16 @@ module Open3
|
|||
# # capture make log
|
||||
# make_log, s = Open3.capture2e("make")
|
||||
#
|
||||
def capture2e(*cmd, stdin_data: nil, binmode: false, **opts)
|
||||
def capture2e(*cmd)
|
||||
if Hash === cmd.last
|
||||
opts = cmd.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
stdin_data = opts.delete(:stdin_data)
|
||||
binmode = opts.delete(:binmode)
|
||||
|
||||
popen2e(*cmd, opts) {|i, oe, t|
|
||||
if binmode
|
||||
i.binmode
|
||||
|
@ -410,7 +451,13 @@ module Open3
|
|||
# stdin.close # send EOF to sort.
|
||||
# p stdout.read #=> " 1\tbar\n 2\tbaz\n 3\tfoo\n"
|
||||
# }
|
||||
def pipeline_rw(*cmds, **opts, &block)
|
||||
def pipeline_rw(*cmds, &block)
|
||||
if Hash === cmds.last
|
||||
opts = cmds.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
in_r, in_w = IO.pipe
|
||||
opts[:in] = in_r
|
||||
in_w.sync = true
|
||||
|
@ -460,7 +507,13 @@ module Open3
|
|||
# p ts[1].value #=> #<Process::Status: pid 24913 exit 0>
|
||||
# }
|
||||
#
|
||||
def pipeline_r(*cmds, **opts, &block)
|
||||
def pipeline_r(*cmds, &block)
|
||||
if Hash === cmds.last
|
||||
opts = cmds.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
out_r, out_w = IO.pipe
|
||||
opts[:out] = out_w
|
||||
|
||||
|
@ -496,7 +549,13 @@ module Open3
|
|||
# i.puts "hello"
|
||||
# }
|
||||
#
|
||||
def pipeline_w(*cmds, **opts, &block)
|
||||
def pipeline_w(*cmds, &block)
|
||||
if Hash === cmds.last
|
||||
opts = cmds.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
in_r, in_w = IO.pipe
|
||||
opts[:in] = in_r
|
||||
in_w.sync = true
|
||||
|
@ -549,7 +608,13 @@ module Open3
|
|||
# p err_r.read # error messages of pdftops and lpr.
|
||||
# }
|
||||
#
|
||||
def pipeline_start(*cmds, **opts, &block)
|
||||
def pipeline_start(*cmds, &block)
|
||||
if Hash === cmds.last
|
||||
opts = cmds.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
if block
|
||||
pipeline_run(cmds, opts, [], [], &block)
|
||||
else
|
||||
|
@ -611,7 +676,13 @@ module Open3
|
|||
# # 106
|
||||
# # 202
|
||||
#
|
||||
def pipeline(*cmds, **opts)
|
||||
def pipeline(*cmds)
|
||||
if Hash === cmds.last
|
||||
opts = cmds.pop.dup
|
||||
else
|
||||
opts = {}
|
||||
end
|
||||
|
||||
pipeline_run(cmds, opts, [], []) {|ts|
|
||||
ts.map(&:value)
|
||||
}
|
||||
|
|
|
@ -316,4 +316,9 @@ class TestOpen3 < Test::Unit::TestCase
|
|||
}
|
||||
end
|
||||
|
||||
def test_integer_and_symbol_key
|
||||
command = [RUBY, '-e', 'puts "test_integer_and_symbol_key"']
|
||||
out, status = Open3.capture2(*command, :in => IO::NULL, 3 => IO::NULL)
|
||||
assert_equal("test_integer_and_symbol_key\n", out)
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче