Class: Homebrew::Cmd::Untrust Private

Inherits:
AbstractCommand show all
Defined in:
cmd/untrust.rb,
sorbet/rbi/dsl/homebrew/cmd/untrust.rbi

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Defined Under Namespace

Classes: Args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_upgradable

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::Cmd::Untrust::Args

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/untrust.rbi', line 10

def args; end

#runvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'cmd/untrust.rb', line 31

def run
  if args.no_named?
    types = selected_type ? [selected_type] : [:tap, :formula, :cask, :command]
    printed = T.let(false, T::Boolean)
    types.each do |type|
      values = Homebrew::Trust.untrusted_taps.flat_map do |tap|
        case type
        when :tap
          [tap.name]
        when :formula
          tap.formula_files.filter_map do |file|
            name = file.basename(file.extname).to_s
            full_name = "#{tap.name}/#{name}"
            full_name unless Homebrew::Trust.trusted?(:formula, full_name)
          end
        when :cask
          tap.cask_files.filter_map do |file|
            name = file.basename(file.extname).to_s
            full_name = "#{tap.name}/#{name}"
            full_name unless Homebrew::Trust.trusted?(:cask, full_name)
          end
        when :command
          tap.command_files.filter_map do |file|
            name = file.basename(file.extname).to_s.delete_prefix("brew-")
            full_name = "#{tap.name}/#{name}"
            full_name unless Homebrew::Trust.trusted?(:command, full_name)
          end
        else
          raise "Unsupported trust type: #{type}"
        end
      end.sort
      next if values.empty?

      label = case type
      when :tap then "taps"
      when :formula then "formulae"
      when :cask then "casks"
      when :command then "commands"
      else raise "Unsupported trust type: #{type}"
      end
      puts "Untrusted #{label}:"
      values.each { |value| puts "  #{value}" }
      printed = true
    end

    puts "No untrusted taps, formulae, casks or commands." unless printed
    return
  end

  args.named.each do |name|
    item_types = [:formula, :cask, :command]
    type, trust_name = Homebrew::Trust.target(name, type: selected_type, include_existing: true)
    if type == :tap && !Tap.remote_reference?(trust_name) && Tap.fetch(trust_name).official?
      puts "Official tap #{trust_name} is always trusted."
      next
    end

    removed = Homebrew::Trust.untrust!(type, trust_name)
    if type == :tap
      item_types.each do |item_type|
        Homebrew::Trust.trusted_entries(item_type).each do |entry|
          removed = true if entry.start_with?("#{trust_name}/") && Homebrew::Trust.untrust!(item_type, entry)
        end
      end
    end
    action = removed ? "Untrusted" : "Not trusted"

    puts "#{action} #{type}: #{trust_name}"
  end
end