| 
									
										
										
										
											2023-03-03 18:54:49 -08:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 17:57:36 -05:00
										 |  |  | require "extend/ENV" | 
					
						
							| 
									
										
										
										
											2015-11-13 16:43:43 +01:00
										 |  |  | require "build_environment" | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  | require "utils/shell" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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) } | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |   def __env_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2019-10-30 18:52:02 +00:00
										 |  |  |         Summarise Homebrew's build environment as a plain list. | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         If the command's output is sent through a pipe and no shell is specified, | 
					
						
							|  |  |  |         the list is formatted for export to `bash`(1) unless `--plain` is passed. | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |       flag   "--shell=", | 
					
						
							|  |  |  |              description: "Generate a list of environment variables for the specified shell, " \ | 
					
						
							|  |  |  |                           "or `--shell=auto` to detect the current shell." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |       switch "--plain", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Generate plain output even when piped." | 
					
						
							| 
									
										
										
										
											2021-01-10 14:26:40 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |       named_args :formula | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-23 18:45:40 +01:00
										 |  |  |   sig { void } | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def __env | 
					
						
							| 
									
										
										
										
											2020-07-23 06:25:35 +02:00
										 |  |  |     args = __env_args.parse | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-18 14:46:48 +00:00
										 |  |  |     ENV.activate_extensions! | 
					
						
							|  |  |  |     ENV.deps = args.named.to_formulae if superenv?(nil) | 
					
						
							| 
									
										
										
										
											2020-07-28 02:04:50 +02:00
										 |  |  |     ENV.setup_build_environment | 
					
						
							| 
									
										
										
										
											2014-09-14 01:26:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |     shell = if args.plain? | 
					
						
							|  |  |  |       nil | 
					
						
							|  |  |  |     elsif args.shell.nil? | 
					
						
							|  |  |  |       :bash unless $stdout.tty? | 
					
						
							|  |  |  |     elsif args.shell == "auto" | 
					
						
							|  |  |  |       Utils::Shell.parent || Utils::Shell.preferred | 
					
						
							|  |  |  |     elsif args.shell | 
					
						
							|  |  |  |       Utils::Shell.from_path(args.shell) | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if shell.nil? | 
					
						
							| 
									
										
										
										
											2023-03-03 18:41:19 -08:00
										 |  |  |       BuildEnvironment.dump ENV.to_h | 
					
						
							| 
									
										
										
										
											2012-03-02 00:59:22 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2022-08-11 09:35:02 +02:00
										 |  |  |       BuildEnvironment.keys(ENV.to_h).each do |key| | 
					
						
							| 
									
										
										
										
											2020-11-23 18:15:48 +01:00
										 |  |  |         puts Utils::Shell.export_value(key, ENV.fetch(key), shell) | 
					
						
							| 
									
										
										
										
											2018-07-26 10:48:25 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-02 00:59:22 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |