Port Homebrew::Cmd::Uses
This commit is contained in:
parent
1362890f2a
commit
fdc95d02c8
@ -1,22 +1,21 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
# `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.
|
||||
|
||||
require "abstract_command"
|
||||
require "formula"
|
||||
require "cli/parser"
|
||||
require "cask/caskroom"
|
||||
require "dependencies_helpers"
|
||||
require "ostruct"
|
||||
|
||||
module Homebrew
|
||||
extend DependenciesHelpers
|
||||
module Cmd
|
||||
# `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.
|
||||
class Uses < AbstractCommand
|
||||
include DependenciesHelpers
|
||||
|
||||
sig { returns(CLI::Parser) }
|
||||
def self.uses_args
|
||||
Homebrew::CLI::Parser.new do
|
||||
cmd_args do
|
||||
description <<~EOS
|
||||
Show formulae and casks that specify <formula> as a dependency; that is, show dependents
|
||||
of <formula>. When given multiple formula arguments, show the intersection
|
||||
@ -53,11 +52,9 @@ module Homebrew
|
||||
|
||||
named_args :formula, min: 1
|
||||
end
|
||||
end
|
||||
|
||||
def self.uses
|
||||
args = uses_args.parse
|
||||
|
||||
sig { override.void }
|
||||
def run
|
||||
Formulary.enable_factory_cache!
|
||||
|
||||
used_formulae_missing = false
|
||||
@ -80,7 +77,7 @@ module Homebrew
|
||||
!args.include_optional? &&
|
||||
!args.skip_recommended?
|
||||
|
||||
uses = intersection_of_dependents(use_runtime_dependents, used_formulae, args:)
|
||||
uses = intersection_of_dependents(use_runtime_dependents, used_formulae)
|
||||
|
||||
return if uses.empty?
|
||||
|
||||
@ -88,7 +85,9 @@ module Homebrew
|
||||
odie "Missing formulae should not have dependents!" if used_formulae_missing
|
||||
end
|
||||
|
||||
def self.intersection_of_dependents(use_runtime_dependents, used_formulae, args:)
|
||||
private
|
||||
|
||||
def intersection_of_dependents(use_runtime_dependents, used_formulae)
|
||||
recursive = args.recursive?
|
||||
show_formulae_and_casks = !args.formula? && !args.cask?
|
||||
includes, ignores = args_includes_ignores(args)
|
||||
@ -138,7 +137,7 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
|
||||
def self.select_used_dependents(dependents, used_formulae, recursive, includes, ignores)
|
||||
def select_used_dependents(dependents, used_formulae, recursive, includes, ignores)
|
||||
dependents.select do |d|
|
||||
deps = if recursive
|
||||
recursive_includes(Dependency, d, includes, ignores)
|
||||
@ -164,4 +163,6 @@ module Homebrew
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cmd/shared_examples/args_parse"
|
||||
require "cmd/uses"
|
||||
require "fileutils"
|
||||
|
||||
RSpec.describe "brew uses" do
|
||||
RSpec.describe Homebrew::Cmd::Uses do
|
||||
include FileUtils
|
||||
|
||||
it_behaves_like "parseable arguments"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user