Skip to content

Commit

Permalink
Allow outputting to file directly
Browse files Browse the repository at this point in the history
  • Loading branch information
adam12 committed Apr 13, 2024
1 parent 1aa59ee commit a811ec0
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions exe/rbz
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,26 @@ require "optionparser"
require "erb"

options = {
main: "main.rb"
main: "main.rb",
output: $stdout
}

parser = OptionParser.new do |parser|
parser.accept(File) do |path|
f = File.open(path, mode: "w")
File.chmod(0o755, path)
f
end

parser.banner = "Usage: rbz [options] folder"
parser.on("-c", "--compile", "Store compiled Ruby iseq")
parser.on("-m FILE", "--main FILE", "Main entrypoint")
parser.on("-o FILE", "--output FILE", File, "Output path (default: stdout)")
end
parser.parse!(into: options)

source = ARGV[0] or abort(parser.to_s)
output = options[:output]
io = StringIO.new

Gem::Package::TarWriter.new(io) do |writer|
Expand All @@ -36,10 +46,10 @@ Gem::Package::TarWriter.new(io) do |writer|
end
end

puts ERB.new(File.read(__FILE__).split("__END__").last.strip, trim_mode: "-").result(binding)
puts
puts "__END__"
puts [Zlib::Deflate.deflate(io.string)].pack("m")
output.puts ERB.new(File.read(__FILE__).split("__END__").last.strip, trim_mode: "-").result(binding)
output.puts
output.puts "__END__"
output.puts [Zlib::Deflate.deflate(io.string)].pack("m")

__END__

Expand Down

0 comments on commit a811ec0

Please sign in to comment.