2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2018-02-27 12:07:30 +00:00
|
|
|
|
|
|
|
module Homebrew
|
|
|
|
module_function
|
|
|
|
|
2018-10-08 22:48:52 -04:00
|
|
|
def ruby_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2019-08-06 14:17:17 -04:00
|
|
|
`ruby` (`-e` <text>|<file>)
|
2018-10-08 22:48:52 -04:00
|
|
|
|
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`.
|
2018-10-08 22:48:52 -04:00
|
|
|
EOS
|
2019-09-13 19:17:41 +02:00
|
|
|
switch "-r",
|
|
|
|
description: "Load a library using `require`."
|
2018-10-08 22:48:52 -04:00
|
|
|
switch "-e",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Execute the given text string as a script."
|
2018-10-08 22:48:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-27 12:07:30 +00:00
|
|
|
def ruby
|
2018-10-08 22:48:52 -04:00
|
|
|
ruby_args.parse
|
|
|
|
|
2019-07-28 02:14:35 +02:00
|
|
|
begin
|
2019-11-06 14:59:27 +00:00
|
|
|
safe_system RUBY_PATH,
|
2019-07-28 02:14:35 +02:00
|
|
|
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
|
|
|
|
"-rglobal", "-rdev-cmd/irb",
|
|
|
|
*ARGV
|
|
|
|
rescue ErrorDuringExecution => e
|
|
|
|
exit e.status.exitstatus
|
|
|
|
end
|
2018-02-27 12:07:30 +00:00
|
|
|
end
|
|
|
|
end
|