Created
August 24, 2024 09:13
-
-
Save dorianmariecom/7e2b959c890260d3fdbc28cfa5f7e73c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "parallel" | |
require "dorian/arguments" | |
def red(string) | |
"\e[31m#{string}\e[0m" | |
end | |
parsed = Dorian::Arguments.parse( | |
output: { aliases: [:o, :out], default: true }, | |
error: { aliases: [:e, :err], default: true }, | |
) | |
Parallel.each($stdin.each_line.to_a) do |it| | |
it = it.strip! | |
read_out, write_out = IO.pipe | |
read_err, write_err = IO.pipe | |
pid = Process.spawn( | |
RbConfig.ruby, | |
"-e", | |
"it = #{it.inspect}", | |
"-e", | |
parsed.arguments.join(" "), | |
out: write_out, | |
err: write_err | |
) | |
write_out.close | |
write_err.close | |
while !read_out.eof? || !read_err.eof? | |
out = read_out.gets | |
puts "[#{it}] #{out.strip}" if out && parsed.options.output | |
err = read_err.gets | |
puts "[#{it}] #{red(err.strip)}" if err && parsed.options.error | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment