| 
									
										
										
										
											2023-03-09 20:32:46 -08:00
										 |  |  | # typed: true | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-01 12:05:21 +01:00
										 |  |  | require "formulary" | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  | require "cask/cask_loader" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2018-03-24 20:04:45 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  | class String | 
					
						
							| 
									
										
										
										
											2015-01-04 21:37:27 -05:00
										 |  |  |   def f(*args) | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  |     Formulary.factory(self, *args) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def c(config: nil) | 
					
						
							|  |  |  |     Cask::CaskLoader.load(self, config: config) | 
					
						
							| 
									
										
										
										
											2012-08-31 08:09:50 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2017-02-23 06:04:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  | class Symbol | 
					
						
							| 
									
										
										
										
											2015-01-04 21:37:27 -05:00
										 |  |  |   def f(*args) | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  |     to_s.f(*args) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def c(config: nil) | 
					
						
							|  |  |  |     to_s.c(config: config) | 
					
						
							| 
									
										
										
										
											2012-08-30 22:54:24 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   def irb_args | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2018-09-28 21:39:52 +05:30
										 |  |  |         Enter the interactive Homebrew Ruby shell. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "--examples", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              description: "Show several examples." | 
					
						
							| 
									
										
										
										
											2018-10-02 19:54:22 +05:30
										 |  |  |       switch "--pry", | 
					
						
							| 
									
										
										
										
											2019-04-30 08:44:35 +01:00
										 |  |  |              env:         :pry, | 
					
						
							|  |  |  |              description: "Use Pry instead of IRB. Implied if `HOMEBREW_PRY` is set." | 
					
						
							| 
									
										
										
										
											2018-03-25 17:48:22 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-07-30 18:25:38 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def irb | 
					
						
							| 
									
										
										
										
											2020-08-03 02:27:20 +01:00
										 |  |  |     # work around IRB modifying ARGV. | 
					
						
							| 
									
										
										
										
											2020-07-31 17:37:36 +02:00
										 |  |  |     args = irb_args.parse(ARGV.dup.freeze) | 
					
						
							| 
									
										
										
										
											2018-03-24 20:04:45 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-04 16:42:34 -08:00
										 |  |  |     clean_argv | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-24 20:04:45 +05:30
										 |  |  |     if args.examples? | 
					
						
							| 
									
										
										
										
											2021-01-24 21:25:12 -05:00
										 |  |  |       puts <<~EOS | 
					
						
							|  |  |  |         'v8'.f # => instance of the v8 formula | 
					
						
							|  |  |  |         :hub.f.latest_version_installed? | 
					
						
							|  |  |  |         :lua.f.methods - 1.methods | 
					
						
							|  |  |  |         :mpd.f.recursive_dependencies.reject(&:installed?) | 
					
						
							| 
									
										
										
										
											2023-03-04 12:25:08 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         'vlc'.c # => instance of the vlc cask | 
					
						
							|  |  |  |         :tsh.c.livecheckable? | 
					
						
							| 
									
										
										
										
											2021-01-24 21:25:12 -05:00
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2018-02-28 11:36:23 +00:00
										 |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 11:04:18 +05:30
										 |  |  |     if args.pry? | 
					
						
							| 
									
										
										
										
											2018-02-28 11:36:23 +00:00
										 |  |  |       require "pry" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       require "irb" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     require "formula" | 
					
						
							|  |  |  |     require "keg" | 
					
						
							| 
									
										
										
										
											2020-08-09 01:34:07 +02:00
										 |  |  |     require "cask" | 
					
						
							| 
									
										
										
										
											2018-02-28 11:36:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-24 21:40:41 -05:00
										 |  |  |     ohai "Interactive Homebrew Shell", "Example commands available with: `brew irb --examples`" | 
					
						
							| 
									
										
										
										
											2018-03-25 11:04:18 +05:30
										 |  |  |     if args.pry? | 
					
						
							| 
									
										
										
										
											2023-03-06 22:37:09 -08:00
										 |  |  |       Pry.config.should_load_rc = false # skip loading .pryrc | 
					
						
							| 
									
										
										
										
											2023-03-07 19:04:19 -08:00
										 |  |  |       Pry.config.history_file = "#{Dir.home}/.brew_pry_history" | 
					
						
							| 
									
										
										
										
											2023-03-06 22:37:09 -08:00
										 |  |  |       Pry.config.memory_size = 100 # max lines to save to history file | 
					
						
							|  |  |  |       Pry.config.prompt_name = "brew" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-28 11:36:23 +00:00
										 |  |  |       Pry.start | 
					
						
							| 
									
										
										
										
											2012-08-06 14:41:55 -04:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2023-03-07 19:04:19 -08:00
										 |  |  |       ENV["IRBRC"] = (HOMEBREW_LIBRARY_PATH/"brew_irbrc").to_s | 
					
						
							| 
									
										
										
										
											2023-03-04 21:18:15 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-21 09:51:28 -04:00
										 |  |  |       IRB.start | 
					
						
							| 
									
										
										
										
											2012-08-06 14:41:55 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-03-04 16:42:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Remove the `--debug`, `--verbose` and `--quiet` options which cause problems | 
					
						
							|  |  |  |   # for IRB and have already been parsed by the CLI::Parser. | 
					
						
							|  |  |  |   def clean_argv | 
					
						
							|  |  |  |     global_options = Homebrew::CLI::Parser | 
					
						
							|  |  |  |                      .global_options | 
					
						
							|  |  |  |                      .flat_map { |options| options[0..1] } | 
					
						
							|  |  |  |     ARGV.reject! { |arg| global_options.include?(arg) } | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-08-06 14:41:55 -04:00
										 |  |  | end |