Port Homebrew::Cmd::InstallCmd

This commit is contained in:
Douglas Eichelberger 2024-03-30 09:36:47 -07:00
parent d25956668d
commit 0fd082a1ff
4 changed files with 386 additions and 382 deletions

View File

@ -217,7 +217,7 @@ class Build
end
begin
args = Homebrew.install_args.parse
args = Homebrew::Cmd::InstallCmd.new.args
Context.current = args.context
error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)

View File

@ -1,6 +1,7 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "abstract_command"
require "cask/config"
require "cask/installer"
require "cask_dependent"
@ -9,13 +10,12 @@ require "formula_installer"
require "development_tools"
require "install"
require "cleanup"
require "cli/parser"
require "upgrade"
module Homebrew
sig { returns(CLI::Parser) }
def self.install_args
Homebrew::CLI::Parser.new do
module Cmd
class InstallCmd < AbstractCommand
cmd_args do
description <<~EOS
Install a <formula> or <cask>. Additional options specific to a <formula> may be
appended to the command.
@ -50,8 +50,9 @@ module Homebrew
}],
[:switch, "--ignore-dependencies", {
description: "An unsupported Homebrew development option to skip installing any dependencies of any " \
"kind. If the dependencies are not already present, the formula will have issues. If you're " \
"not developing Homebrew, consider adjusting your PATH rather than using this option.",
"kind. If the dependencies are not already present, the formula will have issues. If " \
"you're not developing Homebrew, consider adjusting your PATH rather than using this " \
"option.",
}],
[:switch, "--only-dependencies", {
description: "Install the dependencies with specified options but do not install the " \
@ -161,11 +162,9 @@ module Homebrew
named_args [:formula, :cask], min: 1
end
end
def self.install
args = install_args.parse
sig { override.void }
def run
if args.env.present?
# Can't use `replacement: false` because `install_args` are used by
# `build.rb`. Instead, `hide_from_man_page` and don't do anything with
@ -194,8 +193,10 @@ module Homebrew
end
begin
formulae, casks = args.named.to_formulae_and_casks(warn: false)
.partition { |formula_or_cask| formula_or_cask.is_a?(Formula) }
formulae, casks = T.cast(
args.named.to_formulae_and_casks(warn: false).partition { _1.is_a?(Formula) },
[T::Array[Formula], T::Array[Cask::Cask]],
)
rescue FormulaOrCaskUnavailableError, Cask::CaskUnavailableError
cask_tap = CoreCaskTap.instance
if !cask_tap.installed? && (args.cask? || Tap.untapped_official_taps.exclude?(cask_tap.name))
@ -405,4 +406,6 @@ module Homebrew
odie "No #{package_types.join(" or ")} found for #{name}."
end
end
end
end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true
require "cmd/install"
require "cmd/shared_examples/args_parse"
RSpec.describe "brew install" do
RSpec.describe Homebrew::Cmd::InstallCmd do
it_behaves_like "parseable arguments"
it "installs formulae", :integration_test do

View File

@ -70,7 +70,7 @@ RSpec.describe FormulaInstaller do
# rubocop:disable RSpec/NoExpectationExample
specify "basic bottle install" do
allow(DevelopmentTools).to receive(:installed?).and_return(false)
Homebrew.install_args.parse(["testball_bottle"])
Homebrew::Cmd::InstallCmd.new(["testball_bottle"])
temporarily_install_bottle(TestballBottle.new) do |f|
test_basic_formula_setup(f)
end
@ -79,7 +79,7 @@ RSpec.describe FormulaInstaller do
specify "basic bottle install with cellar information on sha256 line" do
allow(DevelopmentTools).to receive(:installed?).and_return(false)
Homebrew.install_args.parse(["testball_bottle_cellar"])
Homebrew::Cmd::InstallCmd.new(["testball_bottle_cellar"])
temporarily_install_bottle(TestballBottleCellar.new) do |f|
test_basic_formula_setup(f)