brew/Library/Homebrew/cmd/leaves.rb

46 lines
1.2 KiB
Ruby
Raw Normal View History

2020-11-25 17:03:23 +01:00
# typed: true
# frozen_string_literal: true
require "formula"
2019-04-17 18:25:08 +09:00
require "cli/parser"
module Homebrew
2020-10-20 12:03:48 +02:00
extend T::Sig
2016-09-26 01:44:51 +02:00
module_function
2020-10-20 12:03:48 +02:00
sig { returns(CLI::Parser) }
2018-11-11 19:13:28 +05:30
def leaves_args
Homebrew::CLI::Parser.new do
description <<~EOS
List installed formulae that are not dependencies of another installed formula.
2018-11-11 19:13:28 +05:30
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."
2020-07-30 18:40:10 +02:00
2021-01-10 14:26:40 -05:00
named_args :none
2018-11-11 19:13:28 +05:30
end
end
def installed_on_request?(leaf)
Tab.for_keg(leaf.any_installed_keg).installed_on_request
end
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
leaves_list.select!(&:installed_on_request?) if args.installed_on_request?
leaves_list.select!(&:installed_as_dependency?) if args.installed_as_dependency?
2018-11-11 19:13:28 +05:30
leaves_list.map(&:full_name).sort.each(&method(:puts))
end
end