Class: Homebrew::Cmd::Uses

Inherits:
AbstractCommand show all
Includes:
DependenciesHelpers
Defined in:
cmd/uses.rb

Overview

brew uses foo bar returns formulae that use both foo and bar If you want the union, run the command twice and concatenate the results. The intersection is harder to achieve with shell tools.

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods included from DependenciesHelpers

#args_includes_ignores, dependents, #recursive_includes, #select_includes

Methods included from Kernel

#disk_usage_readable, #ensure_executable!, #ensure_formula_installed!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #number_readable, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #paths, #pretty_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #quiet_system, #redact_secrets, #redirect_stdout, #require?, #safe_system, #tap_and_name_comparison, #truncate_text_to_approximate_size, #which, #which_all, #which_editor, #with_custom_locale, #with_env, #with_homebrew_path

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.



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
# File 'cmd/uses.rb', line 57

def run
  Formulary.enable_factory_cache!

  used_formulae_missing = false
  used_formulae = begin
    args.named.to_formulae
  rescue FormulaUnavailableError => e
    opoo e
    used_formulae_missing = true
    # If the formula doesn't exist: fake the needed formula object name.
    # This is a legacy use of OpenStruct that should be refactored.
    # rubocop:disable Style/OpenStructUse
    args.named.map { |name| OpenStruct.new name:, full_name: name }
    # rubocop:enable Style/OpenStructUse
  end

  use_runtime_dependents = args.installed? &&
                           !used_formulae_missing &&
                           !args.include_build? &&
                           !args.include_test? &&
                           !args.include_optional? &&
                           !args.skip_recommended?

  uses = intersection_of_dependents(use_runtime_dependents, used_formulae)

  return if uses.empty?

  puts Formatter.columns(uses.map(&:full_name).sort)
  odie "Missing formulae should not have dependents!" if used_formulae_missing
end