60 lines
1.5 KiB
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: false
# 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
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
usage_banner <<~EOS
2019-12-12 19:04:01 -05:00
`--env` [<options>] [<formula>]
2019-01-30 21:29:37 +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",
description: "Generate plain output even when piped."
2019-01-30 21:29:37 +00:00
end
end
2020-11-23 18:45:40 +01:00
sig { void }
def __env
args = __env_args.parse
2019-01-30 21:29:37 +00:00
ENV.activate_extensions!(env: args.env)
ENV.deps = args.named.to_formulae if superenv?(args.env)
ENV.setup_build_environment
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?
BuildEnvironment.dump ENV
else
BuildEnvironment.keys(ENV).each do |key|
2020-11-23 18:15:48 +01:00
puts Utils::Shell.export_value(key, ENV.fetch(key), shell)
end
end
end
end