Add --installed-(on-request/as-dependency) flags

This commit is contained in:
cnnrmnn 2021-05-11 17:32:24 -04:00
parent ef000d0c3b
commit 5cc98d2819

View File

@ -15,14 +15,40 @@ module Homebrew
description <<~EOS description <<~EOS
List installed formulae that are not dependencies of another installed formula. List installed formulae that are not dependencies of another installed formula.
EOS EOS
switch "-r", "--installed-on-request",
description: "Only list leaves that were manually installed."
switch "-p", "--installed-as-dependency",
description: "Only list leaves that were installed as dependencies."
named_args :none named_args :none
end end
end end
def leaves def installed_on_request?(leaf)
leaves_args.parse Tab.for_keg(leaf.any_installed_keg).installed_on_request
end
Formula.installed_formulae_with_no_dependents.map(&:full_name).sort.each(&method(:puts)) def installed_as_dependency?(leaf)
Tab.for_keg(leaf.any_installed_keg).installed_as_dependency
end
def leaves
args = leaves_args.parse
leaves_list = Formula.installed_formulae_with_no_dependents
if args.installed_on_request?
leaves_list.select! do |l|
installed_on_request?(l)
end
end
if args.installed_as_dependency?
leaves_list.select! do |l|
installed_as_dependency?(l)
end
end
leaves_list.map(&:full_name).sort.each(&method(:puts))
end end
end end