From e3427fa64f91c37d1ad4e79622f2c5a4a2306337 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sat, 5 Dec 2020 18:19:56 -0500 Subject: [PATCH 1/3] 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 1b0ef16e8..662d5686b 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 27525453d..5c30afa1d 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 2e6304a46..d853f2703 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\. . From eab1c2ca5386df60b36c777c1fceb460740efeb1 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Sun, 6 Dec 2020 22:21:02 -0500 Subject: [PATCH 2/3] uses: cleanup formula/cask argument handling --- Library/Homebrew/cmd/uses.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 662d5686b..28c580d2a 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -82,21 +82,21 @@ 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?] + only = if args.formula? + :formula + elsif args.cask? + :cask end includes, ignores = args_includes_ignores(args) deps = [] if use_runtime_dependents - if include_formulae + unless only == :cask deps += used_formulae.map(&:runtime_installed_formula_dependents) .reduce(&:&) .select(&:any_version_installed?) end - if include_casks + unless only == :formula deps += select_used_dependents( dependents(Cask::Caskroom.casks(config: Cask::Config.from_args(args))), used_formulae, recursive, includes, ignores @@ -105,8 +105,10 @@ module Homebrew deps else - deps += args.installed? ? Formula.installed : Formula.to_a if include_formulae - if include_casks + unless only == :cask + deps += args.installed? ? Formula.installed : Formula.to_a + end + unless only == :formula deps += args.installed? ? Cask::Caskroom.casks(config: Cask::Config.from_args(args)) : Cask::Cask.to_a end From cb4e47338477580bd28eca240daf45d7f2d7eba9 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Mon, 7 Dec 2020 11:12:28 -0500 Subject: [PATCH 3/3] uses: further cleanup formula/cask argument handling --- Library/Homebrew/cmd/uses.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 28c580d2a..a16c76303 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -82,21 +82,17 @@ module Homebrew def intersection_of_dependents(use_runtime_dependents, used_formulae, args:) recursive = args.recursive? - only = if args.formula? - :formula - elsif args.cask? - :cask - end + show_formulae_and_casks = !args.formula? && !args.cask? includes, ignores = args_includes_ignores(args) deps = [] if use_runtime_dependents - unless only == :cask + if show_formulae_and_casks || args.formula? deps += used_formulae.map(&:runtime_installed_formula_dependents) .reduce(&:&) .select(&:any_version_installed?) end - unless only == :formula + if show_formulae_and_casks || args.cask? deps += select_used_dependents( dependents(Cask::Caskroom.casks(config: Cask::Config.from_args(args))), used_formulae, recursive, includes, ignores @@ -105,10 +101,10 @@ module Homebrew deps else - unless only == :cask + if show_formulae_and_casks || args.formula? deps += args.installed? ? Formula.installed : Formula.to_a end - unless only == :formula + if show_formulae_and_casks || args.cask? deps += args.installed? ? Cask::Caskroom.casks(config: Cask::Config.from_args(args)) : Cask::Cask.to_a end