| 
									
										
										
										
											2016-05-26 17:52:58 +02:00
										 |  |  | #:  * `search`, `-S`: | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  | #:    Display all locally available formulae (including tapped ones). | 
					
						
							|  |  |  | #:    No online search is performed. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-10-02 21:56:00 -04:00
										 |  |  | #:  * `search` `--casks`: | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  | #:    Display all locally available casks (including tapped ones). | 
					
						
							|  |  |  | #:    No online search is performed. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:  * `search` [`--desc`] (<text>|`/`<text>`/`): | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  | #:    Perform a substring search of cask tokens and formula names for <text>. If <text> | 
					
						
							|  |  |  | #:    is surrounded with slashes, then it is interpreted as a regular expression. | 
					
						
							| 
									
										
										
										
											2018-06-19 13:48:23 +02:00
										 |  |  | #:    The search for <text> is extended online to official taps. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-06-19 13:48:23 +02:00
										 |  |  | #:    If `--desc` is passed, search formulae with a description matching <text> and | 
					
						
							|  |  |  | #:    casks with a name matching <text>. | 
					
						
							| 
									
										
										
										
											2016-05-26 07:45:25 -07:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:  * `search` (`--debian`|`--fedora`|`--fink`|`--macports`|`--opensuse`|`--ubuntu`) <text>: | 
					
						
							|  |  |  | #:    Search for <text> in the given package manager's list. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2017-03-18 17:02:08 +02:00
										 |  |  | require "missing_formula" | 
					
						
							| 
									
										
										
										
											2015-09-09 13:00:43 +08:00
										 |  |  | require "descriptions" | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  | require "cli_parser" | 
					
						
							| 
									
										
										
										
											2018-06-02 20:49:14 +02:00
										 |  |  | require "search" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-02 20:49:14 +02:00
										 |  |  |   extend Search | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |   PACKAGE_MANAGERS = { | 
					
						
							|  |  |  |     macports: ->(query) { "https://www.macports.org/ports.php?by=name&substr=#{query}" }, | 
					
						
							|  |  |  |     fink:     ->(query) { "http://pdb.finkproject.org/pdb/browse.php?summary=#{query}" }, | 
					
						
							|  |  |  |     opensuse: ->(query) { "https://software.opensuse.org/search?q=#{query}" }, | 
					
						
							|  |  |  |     fedora:   ->(query) { "https://apps.fedoraproject.org/packages/s/#{query}" }, | 
					
						
							| 
									
										
										
										
											2018-09-02 16:15:09 +01:00
										 |  |  |     debian: lambda { |query| | 
					
						
							|  |  |  |       "https://packages.debian.org/search?keywords=#{query}&searchon=names&suite=all§ion=all" | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     ubuntu: lambda { |query| | 
					
						
							|  |  |  |       "https://packages.ubuntu.com/search?keywords=#{query}&searchon=names&suite=all§ion=all" | 
					
						
							|  |  |  |     }, | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |   }.freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def search(argv = ARGV) | 
					
						
							|  |  |  |     CLI::Parser.parse(argv) do | 
					
						
							|  |  |  |       switch "--desc" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       package_manager_switches = PACKAGE_MANAGERS.keys.map { |name| "--#{name}" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       package_manager_switches.each do |s| | 
					
						
							|  |  |  |         switch s | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  |       switch "--casks" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |       conflicts(*package_manager_switches) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-02 20:14:54 +01:00
										 |  |  |     if package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } | 
					
						
							| 
									
										
										
										
											2018-06-02 20:50:18 +02:00
										 |  |  |       _, url = package_manager | 
					
						
							|  |  |  |       exec_browser url.call(URI.encode_www_form_component(args.remaining.join(" "))) | 
					
						
							|  |  |  |       return | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  |     if args.remaining.empty? | 
					
						
							|  |  |  |       if args.casks? | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  |         puts Formatter.columns(Cask::Cask.to_a.map(&:full_name).sort) | 
					
						
							| 
									
										
										
										
											2018-06-23 01:31:16 +02:00
										 |  |  |       else | 
					
						
							|  |  |  |         puts Formatter.columns(Formula.full_names.sort) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 16:09:13 +02:00
										 |  |  |       return | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-04-27 15:21:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-18 16:09:13 +02:00
										 |  |  |     query = args.remaining.join(" ") | 
					
						
							|  |  |  |     string_or_regex = query_regexp(query) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.desc? | 
					
						
							|  |  |  |       search_descriptions(string_or_regex) | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-06-13 07:49:01 +02:00
										 |  |  |       remote_results = search_taps(query, silent: true) | 
					
						
							| 
									
										
										
										
											2017-08-15 10:25:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-13 07:49:01 +02:00
										 |  |  |       local_formulae = search_formulae(string_or_regex) | 
					
						
							| 
									
										
										
										
											2018-06-09 12:20:58 +02:00
										 |  |  |       remote_formulae = remote_results[:formulae] | 
					
						
							|  |  |  |       all_formulae = local_formulae + remote_formulae | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-13 07:49:01 +02:00
										 |  |  |       local_casks = search_casks(string_or_regex) | 
					
						
							| 
									
										
										
										
											2018-06-09 12:20:58 +02:00
										 |  |  |       remote_casks = remote_results[:casks] | 
					
						
							|  |  |  |       all_casks = local_casks + remote_casks | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if all_formulae.any? | 
					
						
							|  |  |  |         ohai "Formulae" | 
					
						
							|  |  |  |         puts Formatter.columns(all_formulae) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if all_casks.any? | 
					
						
							|  |  |  |         puts if all_formulae.any? | 
					
						
							|  |  |  |         ohai "Casks" | 
					
						
							|  |  |  |         puts Formatter.columns(all_casks) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-16 22:37:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-15 17:10:25 +08:00
										 |  |  |       if $stdout.tty? | 
					
						
							| 
									
										
										
										
											2018-06-09 12:20:58 +02:00
										 |  |  |         count = all_formulae.count + all_casks.count | 
					
						
							| 
									
										
										
										
											2015-10-15 17:10:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-14 01:39:00 +02:00
										 |  |  |         if reason = MissingFormula.reason(query, silent: true) | 
					
						
							| 
									
										
										
										
											2017-09-24 20:12:58 +01:00
										 |  |  |           if count.positive? | 
					
						
							| 
									
										
										
										
											2015-10-15 17:10:25 +08:00
										 |  |  |             puts | 
					
						
							| 
									
										
										
										
											2017-03-18 17:04:44 +02:00
										 |  |  |             puts "If you meant #{query.inspect} specifically:" | 
					
						
							| 
									
										
										
										
											2015-10-15 17:10:25 +08:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-03-20 20:37:12 +01:00
										 |  |  |           puts reason | 
					
						
							| 
									
										
										
										
											2016-09-10 10:24:57 +01:00
										 |  |  |         elsif count.zero? | 
					
						
							| 
									
										
										
										
											2018-06-09 12:20:58 +02:00
										 |  |  |           puts "No formula or cask found for #{query.inspect}." | 
					
						
							| 
									
										
										
										
											2017-04-24 14:11:04 +01:00
										 |  |  |           GitHub.print_pull_requests_matching(query) | 
					
						
							| 
									
										
										
										
											2012-03-20 16:03:27 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2012-01-11 20:49:08 -06:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-11-14 03:52:59 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-10-15 17:10:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 14:11:04 +01:00
										 |  |  |     return unless $stdout.tty? | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |     return if args.remaining.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-24 14:11:04 +01:00
										 |  |  |     metacharacters = %w[\\ | ( ) [ ] { } ^ $ * + ?].freeze | 
					
						
							|  |  |  |     return unless metacharacters.any? do |char| | 
					
						
							| 
									
										
										
										
											2018-06-01 14:19:00 +02:00
										 |  |  |       args.remaining.any? do |arg| | 
					
						
							| 
									
										
										
										
											2017-04-24 14:11:04 +01:00
										 |  |  |         arg.include?(char) && !arg.start_with?("/") | 
					
						
							| 
									
										
										
										
											2015-04-17 12:07:45 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     ohai <<~EOS | 
					
						
							| 
									
										
										
										
											2017-04-24 14:11:04 +01:00
										 |  |  |       Did you mean to perform a regular expression search? | 
					
						
							|  |  |  |       Surround your query with /slashes/ to search locally by regex. | 
					
						
							|  |  |  |     EOS | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |