42 lines
1.0 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
module_function
def ruby_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
2019-08-06 14:17:17 -04:00
`ruby` (`-e` <text>|<file>)
2019-08-06 14:22:24 -04:00
Run a Ruby instance with Homebrew's libraries loaded, e.g.
`brew ruby -e "puts :gcc.f.deps"` or `brew ruby script.rb`.
EOS
2020-08-03 12:38:15 +01:00
flag "-r=",
description: "Load a library using `require`."
flag "-e=",
description: "Execute the given text string as a script."
end
end
def ruby
2020-08-03 12:38:15 +01:00
args = ruby_args.parse
ruby_sys_args = []
ruby_sys_args << "-r#{args.r}" if args.r
ruby_sys_args << "-e #{args.e}" if args.e
ruby_sys_args += args.named
begin
safe_system RUBY_PATH,
ENV["HOMEBREW_RUBY_WARNINGS"],
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rglobal", "-rdev-cmd/irb",
2020-08-03 12:38:15 +01:00
*ruby_sys_args
rescue ErrorDuringExecution => e
exit e.status.exitstatus
end
end
end