| 
									
										
										
										
											2023-03-03 18:54:49 -08:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 15:58:07 -07:00
										 |  |  | require "abstract_command" | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-04-01 15:58:07 -07:00
										 |  |  |   module Cmd | 
					
						
							|  |  |  |     class Env < AbstractCommand | 
					
						
							|  |  |  |       sig { override.returns(String) } | 
					
						
							|  |  |  |       def self.command_name = "--env" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           Summarise Homebrew's build environment as a plain list. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           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 | 
					
						
							|  |  |  |         flag   "--shell=", | 
					
						
							|  |  |  |                description: "Generate a list of environment variables for the specified shell, " \ | 
					
						
							|  |  |  |                             "or `--shell=auto` to detect the current shell." | 
					
						
							|  |  |  |         switch "--plain", | 
					
						
							|  |  |  |                description: "Generate plain output even when piped." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         named_args :formula | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 15:58:07 -07:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							|  |  |  |         ENV.activate_extensions! | 
					
						
							|  |  |  |         ENV.deps = args.named.to_formulae if superenv?(nil) | 
					
						
							|  |  |  |         ENV.setup_build_environment | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         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(T.must(args.shell)) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if shell.nil? | 
					
						
							|  |  |  |           BuildEnvironment.dump ENV.to_h | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           BuildEnvironment.keys(ENV.to_h).each do |key| | 
					
						
							|  |  |  |             puts Utils::Shell.export_value(key, ENV.fetch(key), shell) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											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 |