dev-cmd/ruby: improve args passing

This commit is contained in:
Bo Anderson 2020-08-03 12:38:15 +01:00
parent df16e9f2de
commit b57b83feec

View File

@ -13,21 +13,26 @@ module Homebrew
Run a Ruby instance with Homebrew's libraries loaded, e.g. Run a Ruby instance with Homebrew's libraries loaded, e.g.
`brew ruby -e "puts :gcc.f.deps"` or `brew ruby script.rb`. `brew ruby -e "puts :gcc.f.deps"` or `brew ruby script.rb`.
EOS EOS
switch "-r", flag "-r=",
description: "Load a library using `require`." description: "Load a library using `require`."
switch "-e", flag "-e=",
description: "Execute the given text string as a script." description: "Execute the given text string as a script."
end end
end end
def ruby def ruby
ruby_args.parse 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 begin
safe_system RUBY_PATH, safe_system RUBY_PATH,
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR), "-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rglobal", "-rdev-cmd/irb", "-rglobal", "-rdev-cmd/irb",
*ARGV *ruby_sys_args
rescue ErrorDuringExecution => e rescue ErrorDuringExecution => e
exit e.status.exitstatus exit e.status.exitstatus
end end