From e3427fa64f91c37d1ad4e79622f2c5a4a2306337 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sat, 5 Dec 2020 18:19:56 -0500 Subject: [PATCH] uses: add --formula and --casks flags --- Library/Homebrew/cmd/uses.rb | 42 +++++++++++++++++++++++++----------- docs/Manpage.md | 10 ++++++--- manpages/brew.1 | 12 +++++++++-- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 1b0ef16e8c..662d5686b6 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -23,15 +23,15 @@ module Homebrew usage_banner <<~EOS `uses` [] - Show formulae that specify as a dependency (i.e. show dependents + Show formulae and casks that specify as a dependency (i.e. show dependents of ). When given multiple formula arguments, show the intersection - of formulae that use . By default, `uses` shows all formulae that + of formulae that use . By default, `uses` shows all formulae and casks that specify as a required or recommended dependency for their stable builds. EOS switch "--recursive", description: "Resolve more than one level of dependencies." switch "--installed", - description: "Only list formulae that are currently installed." + description: "Only list formulae and casks that are currently installed." switch "--include-build", description: "Include all formulae that specify as `:build` type dependency." switch "--include-test", @@ -40,7 +40,12 @@ module Homebrew description: "Include all formulae that specify as `:optional` type dependency." switch "--skip-recommended", description: "Skip all formulae that specify as `:recommended` type dependency." + switch "--formula", "--formulae", + description: "Include only formulae." + switch "--cask", "--casks", + description: "Include only casks." + conflicts "--formula", "--cask" min_named :formula end end @@ -77,24 +82,35 @@ module Homebrew def intersection_of_dependents(use_runtime_dependents, used_formulae, args:) recursive = args.recursive? + include_formulae, include_casks = if !args.formula? && !args.cask? + [true, true] + else + [args.formula?, args.cask?] + end includes, ignores = args_includes_ignores(args) + deps = [] if use_runtime_dependents - used_formulae.map(&:runtime_installed_formula_dependents) - .reduce(&:&) - .select(&:any_version_installed?) + - select_used_dependents( + if include_formulae + deps += used_formulae.map(&:runtime_installed_formula_dependents) + .reduce(&:&) + .select(&:any_version_installed?) + end + if include_casks + deps += select_used_dependents( dependents(Cask::Caskroom.casks(config: Cask::Config.from_args(args))), used_formulae, recursive, includes, ignores ) - else - deps = if args.installed? - dependents(Formula.installed + Cask::Caskroom.casks(config: Cask::Config.from_args(args))) - else - dependents(Formula.to_a + Cask::Cask.to_a) end - select_used_dependents(deps, used_formulae, recursive, includes, ignores) + deps + else + deps += args.installed? ? Formula.installed : Formula.to_a if include_formulae + if include_casks + deps += args.installed? ? Cask::Caskroom.casks(config: Cask::Config.from_args(args)) : Cask::Cask.to_a + end + + select_used_dependents(dependents(deps), used_formulae, recursive, includes, ignores) end end diff --git a/docs/Manpage.md b/docs/Manpage.md index 27525453db..5c30afa1d7 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -637,15 +637,15 @@ upgraded formulae or, every 30 days, for all formulae. ### `uses` [*`options`*] *`formula`* -Show formulae that specify *`formula`* as a dependency (i.e. show dependents +Show formulae and casks that specify *`formula`* as a dependency (i.e. show dependents of *`formula`*). When given multiple formula arguments, show the intersection -of formulae that use *`formula`*. By default, `uses` shows all formulae that +of formulae that use *`formula`*. By default, `uses` shows all formulae and casks that specify *`formula`* as a required or recommended dependency for their stable builds. * `--recursive`: Resolve more than one level of dependencies. * `--installed`: - Only list formulae that are currently installed. + Only list formulae and casks that are currently installed. * `--include-build`: Include all formulae that specify *`formula`* as `:build` type dependency. * `--include-test`: @@ -654,6 +654,10 @@ specify *`formula`* as a required or recommended dependency for their stable bui Include all formulae that specify *`formula`* as `:optional` type dependency. * `--skip-recommended`: Skip all formulae that specify *`formula`* as `:recommended` type dependency. +* `--formula`: + Include only formulae. +* `--cask`: + Include only casks. ### `--cache` [*`options`*] [*`formula`*|*`cask`*] diff --git a/manpages/brew.1 b/manpages/brew.1 index 2e6304a461..d853f27039 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -870,7 +870,7 @@ Skip installing cask dependencies\. Also include casks with \fBauto_updates true\fR or \fBversion :latest\fR\. . .SS "\fBuses\fR [\fIoptions\fR] \fIformula\fR" -Show formulae that specify \fIformula\fR as a dependency (i\.e\. show dependents of \fIformula\fR)\. When given multiple formula arguments, show the intersection of formulae that use \fIformula\fR\. By default, \fBuses\fR shows all formulae that specify \fIformula\fR as a required or recommended dependency for their stable builds\. +Show formulae and casks that specify \fIformula\fR as a dependency (i\.e\. show dependents of \fIformula\fR)\. When given multiple formula arguments, show the intersection of formulae that use \fIformula\fR\. By default, \fBuses\fR shows all formulae and casks that specify \fIformula\fR as a required or recommended dependency for their stable builds\. . .TP \fB\-\-recursive\fR @@ -878,7 +878,7 @@ Resolve more than one level of dependencies\. . .TP \fB\-\-installed\fR -Only list formulae that are currently installed\. +Only list formulae and casks that are currently installed\. . .TP \fB\-\-include\-build\fR @@ -896,6 +896,14 @@ Include all formulae that specify \fIformula\fR as \fB:optional\fR type dependen \fB\-\-skip\-recommended\fR Skip all formulae that specify \fIformula\fR as \fB:recommended\fR type dependency\. . +.TP +\fB\-\-formula\fR +Include only formulae\. +. +.TP +\fB\-\-cask\fR +Include only casks\. +. .SS "\fB\-\-cache\fR [\fIoptions\fR] [\fIformula\fR|\fIcask\fR]" Display Homebrew\'s download cache\. See also \fBHOMEBREW_CACHE\fR\. .