Class: Homebrew::DevCmd::Unbottled

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/unbottled.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

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
# File 'dev-cmd/unbottled.rb', line 34

def run
  Formulary.enable_factory_cache!

  @bottle_tag = if (tag = args.tag)
    Utils::Bottles::Tag.from_symbol(tag.to_sym)
  else
    Utils::Bottles.tag
  end

  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

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