/
search.rb
61 lines (54 loc) · 1.84 KB
/
search.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
module Pod
class Command
class Search < Command
self.summary = 'Searches for pods'
self.description = <<-DESC
Searches for pods, ignoring case, whose name matches `QUERY'. If the
`--full' option is specified, this will also search in the summary and
description of the pods.
DESC
self.arguments = '[QUERY]'
def self.options
[
["--full", "Search by name, summary, and description"],
["--stats", "Show additional stats (like GitHub watchers and forks)"],
["--ios", "Restricts the search to Pods supported on iOS"],
["--osx", "Restricts the search to Pods supported on OS X"]
].concat(super)
end
def initialize(argv)
@full_text_search = argv.flag?('full')
@stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios')
@supported_on_osx = argv.flag?('osx')
@query = argv.shift_argument
super
end
def validate!
super
help! "A search query is required." unless @query
end
def run
sets = SourcesManager.search_by_name(@query.strip, @full_text_search)
if @supported_on_ios
sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end
if @supported_on_osx
sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
end
statistics_provider = Config.instance.spec_statistics_provider
sets.each do |set|
begin
if @stats
UI.pod(set, :stats, statistics_provider)
else
UI.pod(set, :normal)
end
rescue DSLError
UI.warn "Skipping `#{set.name}` because the podspec contains errors."
end
end
end
end
end
end