Port Homebrew::Cmd::Pin

This commit is contained in:
Douglas Eichelberger 2024-04-01 09:44:14 -07:00
parent 7725fc62d4
commit c1b1c11a8c
2 changed files with 26 additions and 27 deletions

View File

@ -1,37 +1,35 @@
# typed: true # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "abstract_command"
require "formula" require "formula"
require "cli/parser"
module Homebrew module Homebrew
module_function module Cmd
class Pin < AbstractCommand
cmd_args do
description <<~EOS
Pin the specified <formula>, preventing them from being upgraded when
issuing the `brew upgrade` <formula> command. See also `unpin`.
sig { returns(CLI::Parser) } *Note:* Other packages which depend on newer versions of a pinned formula
def pin_args might not install or run correctly.
Homebrew::CLI::Parser.new do EOS
description <<~EOS
Pin the specified <formula>, preventing them from being upgraded when
issuing the `brew upgrade` <formula> command. See also `unpin`.
*Note:* Other packages which depend on newer versions of a pinned formula named_args :installed_formula, min: 1
might not install or run correctly. end
EOS
named_args :installed_formula, min: 1 sig { override.void }
end def run
end args.named.to_resolved_formulae.each do |f|
if f.pinned?
def pin opoo "#{f.name} already pinned"
args = pin_args.parse elsif !f.pinnable?
onoe "#{f.name} not installed"
args.named.to_resolved_formulae.each do |f| else
if f.pinned? f.pin
opoo "#{f.name} already pinned" end
elsif !f.pinnable? end
onoe "#{f.name} not installed"
else
f.pin
end end
end end
end end

View File

@ -1,8 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cmd/pin"
require "cmd/shared_examples/args_parse" require "cmd/shared_examples/args_parse"
RSpec.describe "brew pin" do RSpec.describe Homebrew::Cmd::Pin do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
it "pins a Formula's version", :integration_test do it "pins a Formula's version", :integration_test do