Port Homebrew::Cmd::Env

This commit is contained in:
Douglas Eichelberger 2024-04-01 15:58:07 -07:00
parent 754151fcb8
commit b56e0b733d
2 changed files with 41 additions and 40 deletions

View File

@ -1,17 +1,18 @@
# typed: strict # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "extend/ENV" require "extend/ENV"
require "build_environment" require "build_environment"
require "utils/shell" require "utils/shell"
require "cli/parser"
module Homebrew module Homebrew
module_function module Cmd
class Env < AbstractCommand
sig { override.returns(String) }
def self.command_name = "--env"
sig { returns(CLI::Parser) } cmd_args do
def __env_args
Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
Summarise Homebrew's build environment as a plain list. Summarise Homebrew's build environment as a plain list.
@ -26,12 +27,9 @@ module Homebrew
named_args :formula named_args :formula
end end
end
sig { void }
def __env
args = __env_args.parse
sig { override.void }
def run
ENV.activate_extensions! ENV.activate_extensions!
ENV.deps = args.named.to_formulae if superenv?(nil) ENV.deps = args.named.to_formulae if superenv?(nil)
ENV.setup_build_environment ENV.setup_build_environment
@ -43,7 +41,7 @@ module Homebrew
elsif args.shell == "auto" elsif args.shell == "auto"
Utils::Shell.parent || Utils::Shell.preferred Utils::Shell.parent || Utils::Shell.preferred
elsif args.shell elsif args.shell
Utils::Shell.from_path(args.shell) Utils::Shell.from_path(T.must(args.shell))
end end
if shell.nil? if shell.nil?
@ -54,4 +52,6 @@ module Homebrew
end end
end end
end end
end
end
end end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/--env"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew --env" do RSpec.describe Homebrew::Cmd::Env do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
describe "--shell=bash", :integration_test do describe "--shell=bash", :integration_test do