Class: Homebrew::Cmd::Leaves Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::Cmd::Leaves
- Defined in:
- cmd/leaves.rb,
sorbet/rbi/dsl/homebrew/cmd/leaves.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
- #args ⇒ Homebrew::Cmd::Leaves::Args private
- #run ⇒ void private
Methods inherited from AbstractCommand
command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?
Methods included from Utils::Output::Mixin
#odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::Cmd::Leaves::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/leaves.rbi', line 10 def args; end |
#run ⇒ void
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.
26 27 28 29 30 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 |
# File 'cmd/leaves.rb', line 26 def run installed = Formula.installed # Build a set of dependency names from tab data to avoid loading full Formula objects # via Formulary.resolve for each dependency (which is expensive I/O). formula_dep_names = installed.flat_map do |f| if (tab_deps = f.any_installed_keg&.runtime_dependencies) tab_deps.filter_map do |dep| full_name = dep["full_name"] next unless full_name Utils.name_from_full_name(full_name) end else # Fallback for installations without tab runtime_dependencies. f.installed_runtime_formula_dependencies.map(&:name) end end # Add direct cask formula dependency names; their transitive deps are already in dep_names. cask_dep_names = Cask::Caskroom.casks.flat_map do |cask| CaskDependent.new(cask).deps.map { |dep| Utils.name_from_full_name(dep.name) } end dep_names = T.let((formula_dep_names + cask_dep_names).to_set, T::Set[String]) leaves_list = installed.reject { |f| dep_names.intersect?(f.possible_names) } leaves_list.select! { |leaf| installed_on_request?(leaf) } if args.installed_on_request? leaves_list.select! { |leaf| installed_as_dependency?(leaf) } if args.installed_as_dependency? leaves_list.map(&:full_name) .sort .each { |leaf| puts(leaf) } end |