diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb index bde90fa8f5..f1f5d72eba 100644 --- a/Library/Homebrew/cmd/postinstall.rb +++ b/Library/Homebrew/cmd/postinstall.rb @@ -1,35 +1,33 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "sandbox" require "formula_installer" -require "cli/parser" module Homebrew - module_function + module Cmd + class Postinstall < AbstractCommand + cmd_args do + description <<~EOS + Rerun the post-install steps for . + EOS - sig { returns(CLI::Parser) } - def postinstall_args - Homebrew::CLI::Parser.new do - description <<~EOS - Rerun the post-install steps for . - EOS + named_args :installed_formula, min: 1 + end - named_args :installed_formula, min: 1 - end - end - - def postinstall - args = postinstall_args.parse - - args.named.to_resolved_formulae.each do |f| - ohai "Postinstalling #{f}" - f.install_etc_var - if f.post_install_defined? - fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact) - fi.post_install - else - opoo "#{f}: no `post_install` method was defined in the formula!" + sig { override.void } + def run + args.named.to_resolved_formulae.each do |f| + ohai "Postinstalling #{f}" + f.install_etc_var + if f.post_install_defined? + fi = FormulaInstaller.new(f, **{ debug: args.debug?, quiet: args.quiet?, verbose: args.verbose? }.compact) + fi.post_install + else + opoo "#{f}: no `post_install` method was defined in the formula!" + end + end end end end diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index 4b188af9f4..171f54b389 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -12,13 +12,13 @@ require "cli/parser" require "cmd/postinstall" begin - args = Homebrew.postinstall_args.parse + args = Homebrew::Cmd::Postinstall.new.args error_pipe = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) trap("INT", old_trap) - formula = args.named.to_resolved_formulae.first + formula = T.must(args.named.to_resolved_formulae.first) if args.debug? require "debrew" formula.extend(Debrew::Formula) diff --git a/Library/Homebrew/test/cmd/postinstall_spec.rb b/Library/Homebrew/test/cmd/postinstall_spec.rb index 30a7911c22..4acab78340 100644 --- a/Library/Homebrew/test/cmd/postinstall_spec.rb +++ b/Library/Homebrew/test/cmd/postinstall_spec.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true +require "cmd/postinstall" require "cmd/shared_examples/args_parse" -RSpec.describe "brew postinstall" do +RSpec.describe Homebrew::Cmd::Postinstall do it_behaves_like "parseable arguments" end