Port Homebrew::Cmd::Postinstall

This commit is contained in:
Douglas Eichelberger 2024-04-01 09:53:38 -07:00
parent 31aa89aa7c
commit 427b527335
3 changed files with 26 additions and 27 deletions

View File

@ -1,27 +1,23 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "sandbox" require "sandbox"
require "formula_installer" require "formula_installer"
require "cli/parser"
module Homebrew module Homebrew
module_function module Cmd
class Postinstall < AbstractCommand
sig { returns(CLI::Parser) } cmd_args do
def postinstall_args
Homebrew::CLI::Parser.new do
description <<~EOS description <<~EOS
Rerun the post-install steps for <formula>. Rerun the post-install steps for <formula>.
EOS EOS
named_args :installed_formula, min: 1 named_args :installed_formula, min: 1
end end
end
def postinstall
args = postinstall_args.parse
sig { override.void }
def run
args.named.to_resolved_formulae.each do |f| args.named.to_resolved_formulae.each do |f|
ohai "Postinstalling #{f}" ohai "Postinstalling #{f}"
f.install_etc_var f.install_etc_var
@ -33,4 +29,6 @@ module Homebrew
end end
end end
end end
end
end
end end

View File

@ -12,13 +12,13 @@ require "cli/parser"
require "cmd/postinstall" require "cmd/postinstall"
begin 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 = UNIXSocket.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io)
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
trap("INT", old_trap) trap("INT", old_trap)
formula = args.named.to_resolved_formulae.first formula = T.must(args.named.to_resolved_formulae.first)
if args.debug? if args.debug?
require "debrew" require "debrew"
formula.extend(Debrew::Formula) formula.extend(Debrew::Formula)

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/postinstall"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew postinstall" do RSpec.describe Homebrew::Cmd::Postinstall do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
end end