diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index 1b0ef16e8c374a81c494d44ec15ef785a769cf6f..662d5686b62dba90ad09b126c1e05eb147bfd585 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,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 ) + 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) + 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(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 27525453db7f2e12b602b1539dbb1f2e13fead00..5c30afa1d77002b7ebc218668cc50d3790b002cf 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 2e6304a46156efc685f4aa7c92b78b1e04fc1684..d853f27039e278dd57d296c3ae6931bc1f7dedb8 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\. .