Merge pull request #11368 from cnnrmnn/add-leaves-flags

Add leaves --installed-on-request and --installed-as-dependency flags
This commit is contained in:
Mike McQuaid 2021-05-13 13:33:29 +01:00 committed by GitHub
commit 02a344d432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 51 additions and 5 deletions

View File

@ -105,6 +105,12 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def installed?; end def installed?; end
sig { returns(T::Boolean) }
def installed_on_request?; end
sig { returns(T::Boolean) }
def installed_as_dependency?; end
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def all?; end def all?; end

View File

@ -15,14 +15,35 @@ 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."
conflicts "--installed-on-request", "--installed-as-dependency"
named_args :none named_args :none
end end
end end
def leaves def installed_on_request?(formula)
leaves_args.parse Tab.for_keg(formula.any_installed_keg).installed_on_request
end
Formula.installed_formulae_with_no_dependents.map(&:full_name).sort.each(&method(:puts)) def installed_as_dependency?(formula)
Tab.for_keg(formula.any_installed_keg).installed_as_dependency
end
def leaves
args = leaves_args.parse
leaves_list = Formula.installed_formulae_with_no_dependents
leaves_list.select!(&method(:installed_on_request?)) if args.installed_on_request?
leaves_list.select!(&method(:installed_as_dependency?)) if args.installed_as_dependency?
leaves_list.map(&:full_name)
.sort
.each(&method(:puts))
end end
end end

View File

@ -1170,6 +1170,8 @@ _brew_leaves() {
__brewcomp " __brewcomp "
--debug --debug
--help --help
--installed-as-dependency
--installed-on-request
--quiet --quiet
--verbose --verbose
" "

View File

@ -845,6 +845,8 @@ __fish_brew_complete_arg 'irb' -l verbose -d 'Make some output more verbose'
__fish_brew_complete_cmd 'leaves' 'List installed formulae that are not dependencies of another installed formula' __fish_brew_complete_cmd 'leaves' 'List installed formulae that are not dependencies of another installed formula'
__fish_brew_complete_arg 'leaves' -l debug -d 'Display any debugging information' __fish_brew_complete_arg 'leaves' -l debug -d 'Display any debugging information'
__fish_brew_complete_arg 'leaves' -l help -d 'Show this message' __fish_brew_complete_arg 'leaves' -l help -d 'Show this message'
__fish_brew_complete_arg 'leaves' -l installed-as-dependency -d 'Only list leaves that were installed as dependencies'
__fish_brew_complete_arg 'leaves' -l installed-on-request -d 'Only list leaves that were manually installed'
__fish_brew_complete_arg 'leaves' -l quiet -d 'Make some output more quiet' __fish_brew_complete_arg 'leaves' -l quiet -d 'Make some output more quiet'
__fish_brew_complete_arg 'leaves' -l verbose -d 'Make some output more verbose' __fish_brew_complete_arg 'leaves' -l verbose -d 'Make some output more verbose'

View File

@ -1037,6 +1037,8 @@ _brew_leaves() {
_arguments \ _arguments \
'--debug[Display any debugging information]' \ '--debug[Display any debugging information]' \
'--help[Show this message]' \ '--help[Show this message]' \
'(--installed-on-request)--installed-as-dependency[Only list leaves that were installed as dependencies]' \
'(--installed-as-dependency)--installed-on-request[Only list leaves that were manually installed]' \
'--quiet[Make some output more quiet]' \ '--quiet[Make some output more quiet]' \
'--verbose[Make some output more verbose]' '--verbose[Make some output more verbose]'
} }

View File

@ -313,10 +313,15 @@ the installed formulae or, every 30 days, for all formulae.
* `--skip-cask-deps`: * `--skip-cask-deps`:
Skip installing cask dependencies. Skip installing cask dependencies.
### `leaves` ### `leaves` [*`--installed-on-request`*] [*`--installed-as-dependency`*]
List installed formulae that are not dependencies of another installed formula. List installed formulae that are not dependencies of another installed formula.
* `-r`, `--installed-on-request`:
Only list leaves that were manually installed.
* `-p`, `--installed-as-dependency`:
Only list leaves that were installed as dependencies.
### `link`, `ln` [*`options`*] *`installed_formula`* [...] ### `link`, `ln` [*`options`*] *`installed_formula`* [...]
Symlink all of *`formula`*'s installed files into Homebrew's prefix. This Symlink all of *`formula`*'s installed files into Homebrew's prefix. This

View File

@ -424,9 +424,17 @@ Disable/enable quarantining of downloads (default: enabled)\.
\fB\-\-skip\-cask\-deps\fR \fB\-\-skip\-cask\-deps\fR
Skip installing cask dependencies\. Skip installing cask dependencies\.
. .
.SS "\fBleaves\fR" .SS "\fBleaves\fR [\fI\-\-installed\-on\-request\fR] [\fI\-\-installed\-as\-dependency\fR]"
List installed formulae that are not dependencies of another installed formula\. List installed formulae that are not dependencies of another installed formula\.
. .
.TP
\fB\-r\fR, \fB\-\-installed\-on\-request\fR
Only list leaves that were manually installed\.
.
.TP
\fB\-p\fR, \fB\-\-installed\-as\-dependency\fR
Only list leaves that were installed as dependencies\.
.
.SS "\fBlink\fR, \fBln\fR [\fIoptions\fR] \fIinstalled_formula\fR [\.\.\.]" .SS "\fBlink\fR, \fBln\fR [\fIoptions\fR] \fIinstalled_formula\fR [\.\.\.]"
Symlink all of \fIformula\fR\'s installed files into Homebrew\'s prefix\. This is done automatically when you install formulae but can be useful for DIY installations\. Symlink all of \fIformula\fR\'s installed files into Homebrew\'s prefix\. This is done automatically when you install formulae but can be useful for DIY installations\.
. .