| 
									
										
										
										
											2018-03-16 09:29:31 +00:00
										 |  |  | #:  * `uses` [`--installed`] [`--recursive`] [`--include-build`] [`--include-test`] [`--include-optional`] [`--skip-recommended`] [`--devel`|`--HEAD`] <formulae>: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    Show the formulae that specify <formulae> as a dependency. When given | 
					
						
							|  |  |  | #:    multiple formula arguments, show the intersection of formulae that use | 
					
						
							|  |  |  | #:    <formulae>. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    Use `--recursive` to resolve more than one level of dependencies. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--installed` is passed, only list installed formulae. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-04-16 00:20:04 +08:00
										 |  |  | #:    By default, `uses` shows all formulae that specify <formulae> as a required | 
					
						
							|  |  |  | #:    or recommended dependency. To include the `:build` type dependencies, pass | 
					
						
							| 
									
										
										
										
											2018-03-16 09:29:31 +00:00
										 |  |  | #:    `--include-build`, to include the `:test` type dependencies, pass | 
					
						
							|  |  |  | #:    `--include-test` and to include `:optional` dependencies pass | 
					
						
							|  |  |  | #:    `--include-optional`. To skip `:recommended` type dependencies, pass | 
					
						
							|  |  |  | #:    `--skip-recommended`. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-03-16 09:29:31 +00:00
										 |  |  | #:    By default, `uses` shows usage of <formulae> by stable builds. To find | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    cases where <formulae> is used by development or HEAD build, pass | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    `--devel` or `--HEAD`. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2018-11-11 19:03:08 +05:30
										 |  |  | require "cli_parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-26 11:03:08 -07:00
										 |  |  | # `brew uses foo bar` returns formulae that use both foo and bar | 
					
						
							|  |  |  | # If you want the union, run the command twice and concatenate the results. | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | # The intersection is harder to achieve with shell tools. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-11 19:03:08 +05:30
										 |  |  |   def uses_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							|  |  |  |         `uses` [<options>] <formulae> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Show the formulae that specify <formulae> as a dependency. When given | 
					
						
							|  |  |  |         multiple formula arguments, show the intersection of formulae that use | 
					
						
							|  |  |  |         <formulae>. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         By default, `uses` shows all formulae that specify <formulae> as a required | 
					
						
							|  |  |  |         or recommended dependency. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         By default, `uses` shows usage of <formulae> by stable builds. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       switch "--recursive", | 
					
						
							|  |  |  |         description: "Resolve more than one level of dependencies." | 
					
						
							|  |  |  |       switch "--installed", | 
					
						
							|  |  |  |         description: "Only list installed formulae." | 
					
						
							|  |  |  |       switch "--include-build", | 
					
						
							|  |  |  |         description: "Include all formulae that specify <formulae> as `:build` type dependency." | 
					
						
							|  |  |  |       switch "--include-test", | 
					
						
							|  |  |  |         description: "Include all formulae that specify <formulae> as `:test` type dependency." | 
					
						
							|  |  |  |       switch "--include-optional", | 
					
						
							|  |  |  |         description: "Include all formulae that specify <formulae> as `:optional` type dependency." | 
					
						
							|  |  |  |       switch "--skip-recommended", | 
					
						
							|  |  |  |         description: "Skip all formulae that specify <formulae> as `:recommended` type dependency." | 
					
						
							|  |  |  |       switch "--devel", | 
					
						
							|  |  |  |         description: "Show usage of <formulae> by development build." | 
					
						
							|  |  |  |       switch "--HEAD", | 
					
						
							|  |  |  |         description: "Show usage of <formulae> by HEAD build." | 
					
						
							|  |  |  |       switch :debug | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def uses | 
					
						
							| 
									
										
										
										
											2018-11-11 19:03:08 +05:30
										 |  |  |     uses_args.parse | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     raise FormulaUnspecifiedError if args.remaining.empty? | 
					
						
							| 
									
										
										
										
											2012-01-29 21:42:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-17 15:06:24 +01:00
										 |  |  |     used_formulae_missing = false | 
					
						
							|  |  |  |     used_formulae = begin | 
					
						
							|  |  |  |       ARGV.formulae | 
					
						
							|  |  |  |     rescue FormulaUnavailableError => e | 
					
						
							|  |  |  |       opoo e | 
					
						
							|  |  |  |       used_formulae_missing = true | 
					
						
							|  |  |  |       # If the formula doesn't exist: fake the needed formula object name. | 
					
						
							|  |  |  |       ARGV.named.map { |name| OpenStruct.new name: name, full_name: name } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-11 19:03:08 +05:30
										 |  |  |     formulae = args.installed? ? Formula.installed : Formula | 
					
						
							|  |  |  |     recursive = args.recursive? | 
					
						
							|  |  |  |     only_installed_arg = args.installed? && | 
					
						
							|  |  |  |                          !args.include_build? && | 
					
						
							|  |  |  |                          !args.include_test? && | 
					
						
							|  |  |  |                          !args.include_optional? && | 
					
						
							|  |  |  |                          !args.skip_recommended? | 
					
						
							| 
									
										
										
										
											2018-03-24 16:55:16 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     includes, ignores = argv_includes_ignores(ARGV) | 
					
						
							| 
									
										
										
										
											2013-06-26 12:58:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 13:07:04 -05:00
										 |  |  |     uses = formulae.select do |f| | 
					
						
							| 
									
										
										
										
											2014-03-07 16:56:17 +01:00
										 |  |  |       used_formulae.all? do |ff| | 
					
						
							| 
									
										
										
										
											2017-01-07 13:15:18 +00:00
										 |  |  |         begin | 
					
						
							| 
									
										
										
										
											2018-03-25 12:48:40 +01:00
										 |  |  |           deps = f.runtime_dependencies if only_installed_arg | 
					
						
							| 
									
										
										
										
											2018-03-25 10:11:24 +01:00
										 |  |  |           deps ||= if recursive | 
					
						
							|  |  |  |             recursive_includes(Dependency, f, includes, ignores) | 
					
						
							| 
									
										
										
										
											2017-01-07 13:15:18 +00:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2018-03-25 10:11:24 +01:00
										 |  |  |             reject_ignores(f.deps, ignores, includes) | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-03-24 16:55:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 10:11:24 +01:00
										 |  |  |           deps.any? do |dep| | 
					
						
							| 
									
										
										
										
											2017-01-07 13:15:18 +00:00
										 |  |  |             begin | 
					
						
							|  |  |  |               dep.to_formula.full_name == ff.full_name | 
					
						
							|  |  |  |             rescue | 
					
						
							|  |  |  |               dep.name == ff.name | 
					
						
							|  |  |  |             end | 
					
						
							| 
									
										
										
										
											2017-01-05 00:24:49 +00:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-01-07 13:15:18 +00:00
										 |  |  |         rescue FormulaUnavailableError | 
					
						
							|  |  |  |           # Silently ignore this case as we don't care about things used in | 
					
						
							|  |  |  |           # taps that aren't currently tapped. | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |           next | 
					
						
							| 
									
										
										
										
											2012-03-16 22:00:59 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-01-29 21:42:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-02 07:57:21 +02:00
										 |  |  |     return if uses.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-14 04:17:48 +01:00
										 |  |  |     puts Formatter.columns(uses.map(&:full_name).sort) | 
					
						
							| 
									
										
										
										
											2017-04-17 15:06:24 +01:00
										 |  |  |     odie "Missing formulae should not have dependents!" if used_formulae_missing | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |