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