42 lines
989 B
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# frozen_string_literal: true
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
def ruby_args
Homebrew::CLI::Parser.new do
usage_banner "`ruby` [<options>] (`-e` <text>|<file>)"
description <<~EOS
Run a Ruby instance with Homebrew's libraries loaded. For example,
2019-08-06 14:22:24 -04:00
`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."
named_args :file
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
exec(*HOMEBREW_RUBY_EXEC_ARGS,
2020-12-17 15:45:50 +01:00
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rglobal", "-rdev-cmd/irb",
*ruby_sys_args)
end
end