58 lines
1.4 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-06-19 17:57:36 -05:00
require "extend/ENV"
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"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
2019-01-30 21:29:37 +00:00
def __env_args
Homebrew::CLI::Parser.new do
usage_banner <<~EOS
`--env` [<options>]
Show a summary of the Homebrew 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=",
2019-04-30 08:44:35 +01:00
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-04-30 08:44:35 +01:00
description: "Plain output even when piped."
2019-01-30 21:29:37 +00:00
end
end
def __env
2019-01-30 21:29:37 +00:00
__env_args.parse
2013-08-19 12:32:56 -05:00
ENV.activate_extensions!
ENV.deps = ARGV.formulae if superenv?
ENV.setup_build_environment
ENV.universal_binary if ARGV.build_universal?
2019-01-30 21:29:37 +00:00
shell = if args.plain?
nil
elsif args.shell.nil?
2016-08-10 23:19:09 -07:00
# legacy behavior
2019-01-30 21:29:37 +00:00
: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
env_keys = build_env_keys(ENV)
if shell.nil?
dump_build_env ENV
else
env_keys.each do |key|
puts Utils::Shell.export_value(key, ENV[key], shell)
end
end
end
end