2015-08-03 13:09:07 +01:00
|
|
|
require "formula"
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2010-09-11 20:22:54 +01:00
|
|
|
|
2013-06-26 11:03:08 -07:00
|
|
|
# `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.
|
2010-09-11 20:22:54 +01:00
|
|
|
# The intersection is harder to achieve with shell tools.
|
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-11-11 19:03:08 +05:30
|
|
|
def uses_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
|
|
|
usage_banner <<~EOS
|
2019-01-30 21:32:35 +00:00
|
|
|
`uses` [<options>] <formula>
|
2018-11-11 19:03:08 +05:30
|
|
|
|
2019-01-30 21:32:35 +00:00
|
|
|
Show the formulae that specify <formula> as a dependency. When given
|
2018-11-11 19:03:08 +05:30
|
|
|
multiple formula arguments, show the intersection of formulae that use
|
2019-01-30 21:32:35 +00:00
|
|
|
<formula>.
|
2018-11-11 19:03:08 +05:30
|
|
|
|
2019-01-30 21:32:35 +00:00
|
|
|
By default, `uses` shows all formulae that specify <formula> as a required
|
2018-11-11 19:03:08 +05:30
|
|
|
or recommended dependency.
|
|
|
|
|
2019-01-30 21:32:35 +00:00
|
|
|
By default, `uses` shows usage of <formula> by stable builds.
|
2018-11-11 19:03:08 +05:30
|
|
|
EOS
|
|
|
|
switch "--recursive",
|
|
|
|
description: "Resolve more than one level of dependencies."
|
|
|
|
switch "--installed",
|
|
|
|
description: "Only list installed formulae."
|
|
|
|
switch "--include-build",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Include all formulae that specify <formula> as `:build` type dependency."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch "--include-test",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Include all formulae that specify <formula> as `:test` type dependency."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch "--include-optional",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Include all formulae that specify <formula> as `:optional` type dependency."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch "--skip-recommended",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Skip all formulae that specify <formula> as `:recommended` type dependency."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch "--devel",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Show usage of <formula> by development build."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch "--HEAD",
|
2019-01-30 21:32:35 +00:00
|
|
|
description: "Show usage of <formula> by HEAD build."
|
2018-11-11 19:03:08 +05:30
|
|
|
switch :debug
|
2019-01-29 19:39:41 +00:00
|
|
|
conflicts "--devel", "--HEAD"
|
2018-11-11 19:03:08 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-11 20:22:54 +01:00
|
|
|
def uses
|
2018-11-11 19:03:08 +05:30
|
|
|
uses_args.parse
|
|
|
|
|
|
|
|
raise FormulaUnspecifiedError if args.remaining.empty?
|
2012-01-29 21:42:09 -08:00
|
|
|
|
2017-04-17 15:06:24 +01:00
|
|
|
used_formulae_missing = false
|
|
|
|
used_formulae = begin
|
|
|
|
ARGV.formulae
|
|
|
|
rescue FormulaUnavailableError => e
|
|
|
|
opoo e
|
|
|
|
used_formulae_missing = true
|
|
|
|
# If the formula doesn't exist: fake the needed formula object name.
|
|
|
|
ARGV.named.map { |name| OpenStruct.new name: name, full_name: name }
|
|
|
|
end
|
|
|
|
|
2018-11-11 19:03:08 +05:30
|
|
|
formulae = args.installed? ? Formula.installed : Formula
|
|
|
|
recursive = args.recursive?
|
|
|
|
only_installed_arg = args.installed? &&
|
|
|
|
!args.include_build? &&
|
|
|
|
!args.include_test? &&
|
|
|
|
!args.include_optional? &&
|
|
|
|
!args.skip_recommended?
|
2018-03-24 16:55:16 +00:00
|
|
|
|
|
|
|
includes, ignores = argv_includes_ignores(ARGV)
|
2013-06-26 12:58:41 -05:00
|
|
|
|
2014-04-07 13:07:04 -05:00
|
|
|
uses = formulae.select do |f|
|
2014-03-07 16:56:17 +01:00
|
|
|
used_formulae.all? do |ff|
|
2017-01-07 13:15:18 +00:00
|
|
|
begin
|
2018-03-25 12:48:40 +01:00
|
|
|
deps = f.runtime_dependencies if only_installed_arg
|
2018-03-25 10:11:24 +01:00
|
|
|
deps ||= if recursive
|
|
|
|
recursive_includes(Dependency, f, includes, ignores)
|
2017-01-07 13:15:18 +00:00
|
|
|
else
|
2018-03-25 10:11:24 +01:00
|
|
|
reject_ignores(f.deps, ignores, includes)
|
2016-09-10 10:24:57 +01:00
|
|
|
end
|
2018-03-24 16:55:16 +00:00
|
|
|
|
2018-03-25 10:11:24 +01:00
|
|
|
deps.any? do |dep|
|
2017-01-07 13:15:18 +00:00
|
|
|
begin
|
|
|
|
dep.to_formula.full_name == ff.full_name
|
|
|
|
rescue
|
|
|
|
dep.name == ff.name
|
|
|
|
end
|
2017-01-05 00:24:49 +00:00
|
|
|
end
|
2017-01-07 13:15:18 +00:00
|
|
|
rescue FormulaUnavailableError
|
|
|
|
# Silently ignore this case as we don't care about things used in
|
|
|
|
# taps that aren't currently tapped.
|
2017-10-07 00:31:28 +02:00
|
|
|
next
|
2012-03-16 22:00:59 -07:00
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
2012-01-29 21:42:09 -08:00
|
|
|
|
2016-10-02 07:57:21 +02:00
|
|
|
return if uses.empty?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2017-10-14 04:17:48 +01:00
|
|
|
puts Formatter.columns(uses.map(&:full_name).sort)
|
2017-04-17 15:06:24 +01:00
|
|
|
odie "Missing formulae should not have dependents!" if used_formulae_missing
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|