Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tvOS and any possible future platforms. #14

Merged
merged 3 commits into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

## Master

* Perform regexp escape on individual query words before joining them
##### Enhancements

* Add support for tvOS and any possible future platforms.
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[#11](https://github.com/CocoaPods/cocoapods-search/issues/11)

* Perform regexp escape on individual query words before joining them.
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[#8](https://github.com/CocoaPods/cocoapods-search/issues/8)

Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ source 'https://rubygems.org'
gemspec

group :development do
gem 'cocoapods'
gem 'cocoapods', :git => "https://github.com/CocoaPods/CocoaPods.git", :branch => 'master'
gem 'cocoapods-core', :git => "https://github.com/CocoaPods/Core.git", :branch => 'master'
gem 'bacon'
gem 'mocha-on-bacon'
gem 'prettybacon'
Expand Down
74 changes: 45 additions & 29 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
GIT
remote: https://github.com/CocoaPods/CocoaPods.git
revision: f7578085842f7a8caca5d8ebbbd99f91a6474e45
branch: master
specs:
cocoapods (0.39.0)
activesupport (>= 4.0.2)
claide (~> 0.9.1)
cocoapods-core (= 0.39.0)
cocoapods-downloader (~> 0.9.3)
cocoapods-plugins (~> 0.4.2)
cocoapods-search (~> 0.1.0)
cocoapods-stats (~> 0.6.2)
cocoapods-trunk (~> 0.6.4)
cocoapods-try (~> 0.5.1)
colored (~> 1.2)
escape (~> 0.0.4)
molinillo (~> 0.4.0)
nap (~> 1.0)
xcodeproj (~> 0.28.2)

GIT
remote: https://github.com/CocoaPods/Core.git
revision: ce26e1eb797a6ad1f1d94b0304a50c491bc41237
branch: master
specs:
cocoapods-core (0.39.0)
activesupport (>= 4.0.2)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)

PATH
remote: .
specs:
Expand All @@ -6,41 +37,22 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (4.2.3)
activesupport (4.2.4)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
bacon (1.2.0)
claide (0.9.1)
cocoapods (0.38.2)
activesupport (>= 3.2.15)
claide (~> 0.9.1)
cocoapods-core (= 0.38.2)
cocoapods-downloader (~> 0.9.1)
cocoapods-plugins (~> 0.4.2)
cocoapods-stats (~> 0.5.3)
cocoapods-trunk (~> 0.6.1)
cocoapods-try (~> 0.4.5)
colored (~> 1.2)
escape (~> 0.0.4)
molinillo (~> 0.3.1)
nap (~> 0.8)
xcodeproj (~> 0.26.3)
cocoapods-core (0.38.2)
activesupport (>= 3.2.15)
fuzzy_match (~> 2.0.4)
nap (~> 0.8.0)
cocoapods-downloader (0.9.1)
cocoapods-downloader (0.9.3)
cocoapods-plugins (0.4.2)
nap
cocoapods-stats (0.5.3)
nap (~> 0.8)
cocoapods-trunk (0.6.1)
nap (>= 0.8)
cocoapods-stats (0.6.2)
cocoapods-trunk (0.6.4)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (0.4.5)
cocoapods-try (0.5.1)
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
Expand All @@ -52,16 +64,16 @@ GEM
metaclass (~> 0.0.1)
mocha-on-bacon (0.2.2)
mocha (>= 0.13.0)
molinillo (0.3.1)
nap (0.8.0)
molinillo (0.4.0)
nap (1.0.0)
netrc (0.7.8)
prettybacon (0.0.2)
bacon (~> 1.2)
rake (10.4.2)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (0.26.3)
xcodeproj (0.28.2)
activesupport (>= 3)
claide (~> 0.9.1)
colored (~> 1.2)
Expand All @@ -72,8 +84,12 @@ PLATFORMS
DEPENDENCIES
bacon
bundler (~> 1.3)
cocoapods
cocoapods!
cocoapods-core!
cocoapods-search!
mocha-on-bacon
prettybacon
rake

BUNDLED WITH
1.10.6
41 changes: 18 additions & 23 deletions lib/cocoapods-search/command/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ class Search < Command
]

def self.options
[
options = [
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, description, and authors'],
['--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'],
['--watchos', 'Restricts the search to Pods supported on Watch OS'],
['--web', 'Searches on cocoapods.org'],
].concat(super.reject { |option, _| option == '--silent' })
]
options += Platform.all.map do |platform|
["--#{platform.name.to_s}", "Restricts the search to Pods supported on #{Platform.string_name(platform.to_sym)}"]
end
options.concat(super.reject { |option, _| option == '--silent' })
end

def initialize(argv)
@use_regex = argv.flag?('regex')
@full_text_search = argv.flag?('full')
@stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios')
@supported_on_osx = argv.flag?('osx')
@supported_on_watchos = argv.flag?('watchos')
@web = argv.flag?('web')
@platform_filters = Platform.all.map do |platform|
argv.flag?(platform.name.to_s) ? platform.to_sym : nil
end.compact
@query = argv.arguments! unless argv.arguments.empty?
config.silent = false
super
Expand Down Expand Up @@ -61,12 +62,11 @@ def run
end

def web_search
query_parameter = [
('on:osx' if @supported_on_osx),
('on:ios' if @supported_on_ios),
('on:watchos' if @supported_on_watchos),
@query,
].compact.flatten.join(' ')
queries = @platform_filters.map do |platform|
"on:#{platform}"
end
queries += @query
query_parameter = queries.compact.flatten.join(' ')
url = "https://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub('+', '%20')}"
UI.puts("Opening #{url}")
open!(url)
Expand All @@ -78,17 +78,12 @@ def local_search
}.join(' ').strip

sets = SourcesManager.search_by_name(query_regex, @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
if @supported_on_watchos
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:watchos) }

@platform_filters.each do |platform|
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(platform) }
end

sets.each do |set|
sets.each do |set|
begin
if @stats
UI.pod(set, :stats)
Expand Down
26 changes: 24 additions & 2 deletions spec/command/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ module Pod
output.should.not.include? 'BananaLib'
end

it 'restricts the search to Pods supported on tvOS' do
output = run_command('search', '', '--tvos')
output.should.include? 'monkey'
output.should.not.include? 'BananaLib'
end

it 'outputs with the silent parameter' do
output = run_command('search', 'BananaLib', '--silent')
output.should.include? 'BananaLib'
Expand Down Expand Up @@ -115,11 +121,27 @@ module Pod
run_command('search', '--web', '--ios', 'bananalib')
end

it 'includes option --watchos correctly' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Awatchos%20bananalib')
run_command('search', '--web', '--watchos', 'bananalib')
end

it 'includes option --tvos correctly' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Atvos%20bananalib')
run_command('search', '--web', '--tvos', 'bananalib')
end

it 'includes any new platform option correctly' do
Platform.stubs(:all).returns([Platform.ios, Platform.tvos, Platform.new('whateveros')])
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Awhateveros%20bananalib')
run_command('search', '--web', '--whateveros', 'bananalib')
end

it 'does not matter in which order the ios/osx options are set' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Aosx%20on%3Aios%20bananalib')
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Aios%20on%3Aosx%20bananalib')
run_command('search', '--web', '--ios', '--osx', 'bananalib')

Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Aosx%20on%3Aios%20bananalib')
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Aios%20on%3Aosx%20bananalib')
run_command('search', '--web', '--osx', '--ios', 'bananalib')
end
end
Expand Down