diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 1b0ef16e8c374a81c494d44ec15ef785a769cf6f..a16c7630353a91ee0ee6d1d9f1a40505a20eb029 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -23,15 +23,15 @@ module Homebrew usage_banner <<~EOS `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. 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 <formula> as `:build` type dependency." switch "--include-test", @@ -40,7 +40,12 @@ module Homebrew description: "Include all formulae that specify <formula> as `:optional` type dependency." switch "--skip-recommended", description: "Skip all formulae that specify <formula> 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,33 @@ module Homebrew def intersection_of_dependents(use_runtime_dependents, used_formulae, args:) recursive = args.recursive? + show_formulae_and_casks = !args.formula? && !args.cask? 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 show_formulae_and_casks || args.formula? + deps += used_formulae.map(&:runtime_installed_formula_dependents) + .reduce(&:&) + .select(&:any_version_installed?) + end + 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 ) + end + + deps 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) + if show_formulae_and_casks || args.formula? + deps += args.installed? ? Formula.installed : Formula.to_a + end + if show_formulae_and_casks || args.cask? + deps += args.installed? ? Cask::Caskroom.casks(config: Cask::Config.from_args(args)) : Cask::Cask.to_a end - select_used_dependents(deps, used_formulae, recursive, includes, ignores) + select_used_dependents(dependents(deps), used_formulae, recursive, includes, ignores) end end diff --git a/docs/Manpage.md b/docs/Manpage.md index a62fdef9c9a578753ad757511656ae7dfd2dcf09..e1ffc68c25db92cc3bd3a07b255563e63aa88c45 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -640,15 +640,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`: @@ -657,6 +657,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 336d3d920a310b82e9a33d3c934ecdef521887af..6d3ca60a2faaf6a4a2e0e6947b643582f30607d6 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -874,7 +874,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 @@ -882,7 +882,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 @@ -900,6 +900,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\. .