| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 12:07:30 +00:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-10-08 22:48:52 -04:00
										 |  |  |   def ruby_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       usage_banner "`ruby` [<options>] (`-e` <text>|<file>)" | 
					
						
							|  |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2021-01-24 01:59:02 -05:00
										 |  |  |         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`. | 
					
						
							| 
									
										
										
										
											2018-10-08 22:48:52 -04:00
										 |  |  |       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." | 
					
						
							| 
									
										
										
										
											2021-01-18 13:30:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       named_args :file | 
					
						
							| 
									
										
										
										
											2018-10-08 22:48:52 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-27 12:07:30 +00:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2018-10-08 22:48:52 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-17 15:45:50 +01:00
										 |  |  |     exec RUBY_PATH, | 
					
						
							|  |  |  |          ENV["HOMEBREW_RUBY_WARNINGS"], | 
					
						
							|  |  |  |          "-I", $LOAD_PATH.join(File::PATH_SEPARATOR), | 
					
						
							|  |  |  |          "-rglobal", "-rdev-cmd/irb", | 
					
						
							|  |  |  |          *ruby_sys_args | 
					
						
							| 
									
										
										
										
											2018-02-27 12:07:30 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | end |