pin.rb 729 Bytes
Newer Older
Markus Reiter's avatar
Markus Reiter committed
1
# typed: true
2
3
# frozen_string_literal: true

BrewTestBot's avatar
BrewTestBot committed
4
require "formula"
5
require "cli/parser"
6

7
module Homebrew
Markus Reiter's avatar
Markus Reiter committed
8
9
  extend T::Sig

10
11
  module_function

Markus Reiter's avatar
Markus Reiter committed
12
  sig { returns(CLI::Parser) }
13
14
15
  def pin_args
    Homebrew::CLI::Parser.new do
      usage_banner <<~EOS
16
        `pin` <formula>
17

18
19
        Pin the specified <formula>, preventing them from being upgraded when
        issuing the `brew upgrade` <formula> command. See also `unpin`.
20
      EOS
Markus Reiter's avatar
Markus Reiter committed
21

22
      min_named :formula
23
24
25
    end
  end

26
  def pin
Markus Reiter's avatar
Markus Reiter committed
27
    args = pin_args.parse
28

29
    args.named.to_resolved_formulae.each do |f|
30
31
32
33
34
35
36
      if f.pinned?
        opoo "#{f.name} already pinned"
      elsif !f.pinnable?
        onoe "#{f.name} not installed"
      else
        f.pin
      end
37
38
39
    end
  end
end