Class: Homebrew::DevCmd::Unbottled Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/unbottled.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/unbottled.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

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Unbottled::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/dev_cmd/unbottled.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.



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
101
102
103
104
105
106
107
108
109
# File 'dev-cmd/unbottled.rb', line 34

def run
  Formulary.enable_factory_cache!

  @bottle_tag = T.let(
    if (tag = args.tag)
      Utils::Bottles::Tag.from_symbol(tag.to_sym)
    else
      Utils::Bottles.tag
    end,
    T.nilable(Utils::Bottles::Tag),
  )
  return unless @bottle_tag

  if args.lost?
    if args.named.present?
      raise UsageError, "`brew unbottled --lost` cannot be used with formula arguments!"
    elsif !CoreTap.instance.installed?
      raise UsageError, "`brew unbottled --lost` requires `homebrew/core` to be tapped locally!"
    else
      output_lost_bottles
      return
    end
  end

  os = @bottle_tag.system
  arch = if Hardware::CPU::INTEL_ARCHS.include?(@bottle_tag.arch)
    :intel
  elsif Hardware::CPU::ARM_ARCHS.include?(@bottle_tag.arch)
    :arm
  else
    raise "Unknown arch #{@bottle_tag.arch}."
  end

  Homebrew::SimulateSystem.with(os:, arch:) do
    all = args.eval_all?
    if args.total?
      if !all && !Homebrew::EnvConfig.eval_all?
        raise UsageError, "`brew unbottled --total` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
      end

      all = true
    end

    if args.named.blank?
      ohai "Getting formulae..."
    elsif all
      raise UsageError, "Cannot specify formulae when using `--eval-all`/`--total`."
    end

    formulae, all_formulae, formula_installs = formulae_all_installs_from_args(all)
    deps_hash, uses_hash = deps_uses_from_formulae(all_formulae)

    if args.dependents?
      formula_dependents = {}
      formulae = formulae.sort_by do |f|
        dependents = uses_hash[f.name]&.length || 0
        formula_dependents[f.name] ||= dependents
      end.reverse
    elsif all
      output_total(formulae)
      return
    end

    noun, hash = if args.named.present?
      [nil, {}]
    elsif args.dependents?
      ["dependents", formula_dependents]
    else
      ["installs", formula_installs]
    end

    return if hash.nil?

    output_unbottled(formulae, deps_hash, noun, hash, args.named.present?)
  end
end