diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb index 9b7cc843cb..91a9608efe 100644 --- a/Library/Homebrew/cmd/pin.rb +++ b/Library/Homebrew/cmd/pin.rb @@ -1,37 +1,35 @@ -# typed: true +# typed: strict # frozen_string_literal: true +require "abstract_command" require "formula" -require "cli/parser" module Homebrew - module_function + module Cmd + class Pin < AbstractCommand + cmd_args do + description <<~EOS + Pin the specified , preventing them from being upgraded when + issuing the `brew upgrade` command. See also `unpin`. - sig { returns(CLI::Parser) } - def pin_args - Homebrew::CLI::Parser.new do - description <<~EOS - Pin the specified , preventing them from being upgraded when - issuing the `brew upgrade` command. See also `unpin`. + *Note:* Other packages which depend on newer versions of a pinned formula + might not install or run correctly. + EOS - *Note:* Other packages which depend on newer versions of a pinned formula - might not install or run correctly. - EOS + named_args :installed_formula, min: 1 + end - named_args :installed_formula, min: 1 - end - end - - def pin - args = pin_args.parse - - args.named.to_resolved_formulae.each do |f| - if f.pinned? - opoo "#{f.name} already pinned" - elsif !f.pinnable? - onoe "#{f.name} not installed" - else - f.pin + sig { override.void } + def run + args.named.to_resolved_formulae.each do |f| + if f.pinned? + opoo "#{f.name} already pinned" + elsif !f.pinnable? + onoe "#{f.name} not installed" + else + f.pin + end + end end end end diff --git a/Library/Homebrew/test/cmd/pin_spec.rb b/Library/Homebrew/test/cmd/pin_spec.rb index 95fe1180e7..15c978f032 100644 --- a/Library/Homebrew/test/cmd/pin_spec.rb +++ b/Library/Homebrew/test/cmd/pin_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true +require "cmd/pin" require "cmd/shared_examples/args_parse" -RSpec.describe "brew pin" do +RSpec.describe Homebrew::Cmd::Pin do it_behaves_like "parseable arguments" it "pins a Formula's version", :integration_test do