--env: use CLI::Parser.

This commit is contained in:
Mike McQuaid 2019-01-30 21:29:37 +00:00
parent 93799ba71a
commit 515d4c023d
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70

View File

@ -1,36 +1,46 @@
#: * `--env` [`--shell=`(<shell>|`auto`)|`--plain`]:
#: Show a summary of the Homebrew build environment as a plain list.
#:
#: Pass `--shell=`<shell> to generate a list of environment variables for the
#: specified shell, or `--shell=auto` to detect the current shell.
#:
#: 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.
require "extend/ENV"
require "build_environment"
require "utils/shell"
require "cli_parser"
module Homebrew
module_function
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=",
description: "Generate a list of environment variables for the specified shell, " \
"or `--shell=auto` to detect the current shell."
switch "--plain",
description: "Plain output even when piped."
end
end
def __env
__env_args.parse
ENV.activate_extensions!
ENV.deps = ARGV.formulae if superenv?
ENV.setup_build_environment
ENV.universal_binary if ARGV.build_universal?
shell_value = ARGV.value("shell")
if ARGV.include?("--plain")
shell = nil
elsif shell_value.nil?
shell = if args.plain?
nil
elsif args.shell.nil?
# legacy behavior
shell = :bash unless $stdout.tty?
elsif shell_value == "auto"
shell = Utils::Shell.parent || Utils::Shell.preferred
elsif shell_value
shell = Utils::Shell.from_path(shell_value)
:bash unless $stdout.tty?
elsif args.shell == "auto"
Utils::Shell.parent || Utils::Shell.preferred
elsif args.shell
Utils::Shell.from_path(args.shell)
end
env_keys = build_env_keys(ENV)