Commit f19747e0 authored by Emma Koszinowski's avatar Emma Koszinowski

Added the cocoapods-search plugin to CocoaPods

Added the cocoapods gem 'cocoapods-search' to the Gemfile
Added the dependency to the cocoapods.gemspec
Deleted the source code for search and the source code for the search specs
parent 5955c55f
...@@ -18,6 +18,7 @@ group :development do ...@@ -18,6 +18,7 @@ group :development do
cp_gem 'cocoapods-core', 'Core' cp_gem 'cocoapods-core', 'Core'
cp_gem 'cocoapods-downloader', 'cocoapods-downloader' cp_gem 'cocoapods-downloader', 'cocoapods-downloader'
cp_gem 'cocoapods-plugins', 'cocoapods-plugins' cp_gem 'cocoapods-plugins', 'cocoapods-plugins'
cp_gem 'cocoapods-search', 'cocoapods-search'
cp_gem 'cocoapods-stats', 'cocoapods-stats' cp_gem 'cocoapods-stats', 'cocoapods-stats'
cp_gem 'cocoapods-trunk', 'cocoapods-trunk' cp_gem 'cocoapods-trunk', 'cocoapods-trunk'
cp_gem 'cocoapods-try', 'cocoapods-try' cp_gem 'cocoapods-try', 'cocoapods-try'
......
...@@ -47,6 +47,13 @@ GIT ...@@ -47,6 +47,13 @@ GIT
cocoapods-plugins (0.4.2) cocoapods-plugins (0.4.2)
nap nap
GIT
remote: https://github.com/CocoaPods/cocoapods-search.git
revision: 4af63d57cf6a4746a94739eb15f74ffa073e95a2
branch: master
specs:
cocoapods-search (0.0.1)
GIT GIT
remote: https://github.com/CocoaPods/cocoapods-stats.git remote: https://github.com/CocoaPods/cocoapods-stats.git
revision: 464ed12e3d0d60ca942c7cf30e06ef4e11c86b12 revision: 464ed12e3d0d60ca942c7cf30e06ef4e11c86b12
...@@ -79,6 +86,7 @@ PATH ...@@ -79,6 +86,7 @@ PATH
cocoapods-core (= 0.39.0.beta.3) cocoapods-core (= 0.39.0.beta.3)
cocoapods-downloader (~> 0.9.3) cocoapods-downloader (~> 0.9.3)
cocoapods-plugins (~> 0.4.2) cocoapods-plugins (~> 0.4.2)
cocoapods-search (~> 0.0.1)
cocoapods-stats (~> 0.6.1) cocoapods-stats (~> 0.6.1)
cocoapods-trunk (~> 0.6.4) cocoapods-trunk (~> 0.6.4)
cocoapods-try (~> 0.5.1) cocoapods-try (~> 0.5.1)
...@@ -191,6 +199,7 @@ DEPENDENCIES ...@@ -191,6 +199,7 @@ DEPENDENCIES
cocoapods-dependencies cocoapods-dependencies
cocoapods-downloader! cocoapods-downloader!
cocoapods-plugins! cocoapods-plugins!
cocoapods-search!
cocoapods-stats! cocoapods-stats!
cocoapods-trunk! cocoapods-trunk!
cocoapods-try! cocoapods-try!
......
...@@ -32,6 +32,7 @@ Gem::Specification.new do |s| ...@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'xcodeproj', '~> 0.27.1' s.add_runtime_dependency 'xcodeproj', '~> 0.27.1'
s.add_runtime_dependency 'cocoapods-downloader', '~> 0.9.3' s.add_runtime_dependency 'cocoapods-downloader', '~> 0.9.3'
s.add_runtime_dependency 'cocoapods-plugins', '~> 0.4.2' s.add_runtime_dependency 'cocoapods-plugins', '~> 0.4.2'
s.add_runtime_dependency 'cocoapods-search', '~> 0.0.1'
s.add_runtime_dependency 'cocoapods-stats', '~> 0.6.1' s.add_runtime_dependency 'cocoapods-stats', '~> 0.6.1'
s.add_runtime_dependency 'cocoapods-try', '~> 0.5.1' s.add_runtime_dependency 'cocoapods-try', '~> 0.5.1'
s.add_runtime_dependency 'cocoapods-trunk', '~> 0.6.4' s.add_runtime_dependency 'cocoapods-trunk', '~> 0.6.4'
......
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 = [
CLAide::Argument.new('QUERY', true),
]
def self.options
[
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--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'],
['--web', 'Searches on cocoapods.org'],
].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')
@web = argv.flag?('web')
@query = argv.arguments! unless argv.arguments.empty?
config.silent = false
super
end
def validate!
super
help! 'A search query is required.' unless @query
unless @web || !@use_regex
begin
/#{@query.join(' ').strip}/
rescue RegexpError
help! 'A valid regular expression is required.'
end
end
end
def run
ensure_master_spec_repo_exists!
if @web
web_search
else
local_search
end
end
extend Executable
executable :open
def web_search
query_parameter = [
('on:osx' if @supported_on_osx),
('on:ios' if @supported_on_ios),
@query,
].compact.flatten.join(' ')
url = "http://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub('+', '%20')}"
UI.puts("Opening #{url}")
open!(url)
end
def local_search
query_regex = @query.join(' ').strip
query_regex = Regexp.escape(query_regex) unless @use_regex
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
sets.each do |set|
begin
if @stats
UI.pod(set, :stats)
else
UI.pod(set, :normal)
end
rescue DSLError
UI.warn "Skipping `#{set.name}` because the podspec contains errors."
end
end
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Command::Search do
extend SpecHelper::TemporaryRepos
before do
@test_source = Source.new(fixture('spec-repos/test_repo'))
Source::Aggregate.any_instance.stubs(:sources).returns([@test_source])
SourcesManager.updated_search_index = nil
end
it 'runs with correct parameters' do
lambda { run_command('search', 'JSON') }.should.not.raise
lambda { run_command('search', 'JSON', '--full') }.should.not.raise
end
it 'complains for wrong parameters' do
lambda { run_command('search') }.should.raise CLAide::Help
lambda { run_command('search', 'too', '--wrong') }.should.raise CLAide::Help
lambda { run_command('search', '--wrong') }.should.raise CLAide::Help
end
it 'searches for a pod with name matching the given query ignoring case' do
output = run_command('search', 'json')
output.should.include? 'JSONKit'
end
it 'searches for a pod with name, summary, or description matching the given query ignoring case' do
output = run_command('search', 'Engelhart', '--full')
output.should.include? 'JSONKit'
end
it 'restricts the search to Pods supported on iOS' do
output = run_command('search', 'BananaLib', '--ios')
output.should.include? 'BananaLib'
Specification.any_instance.stubs(:available_platforms).returns([Platform.osx])
output = run_command('search', 'BananaLib', '--ios')
output.should.not.include? 'BananaLib'
end
it 'restricts the search to Pods supported on OS X' do
output = run_command('search', 'BananaLib', '--osx')
output.should.not.include? 'BananaLib'
end
it 'outputs with the silent parameter' do
output = run_command('search', 'BananaLib', '--silent')
output.should.include? 'BananaLib'
end
it 'shows a friendly message when locally searching with invalid regex' do
lambda { run_command('search', '--regex', '+') }.should.raise CLAide::Help
end
it 'does not try to validate the query as a regex with plain-text search' do
lambda { run_command('search', '+') }.should.not.raise CLAide::Help
end
it 'uses regex search when asked for regex mode' do
output = run_command('search', '--regex', 'Ba(na)+Lib')
output.should.include? 'BananaLib'
output.should.not.include? 'Pod+With+Plus+Signs'
output.should.not.include? 'JSONKit'
end
it 'uses plain-text search when not asked for regex mode' do
output = run_command('search', 'Pod+With+Plus+Signs')
output.should.include? 'Pod+With+Plus+Signs'
output.should.not.include? 'BananaLib'
end
describe 'option --web' do
extend SpecHelper::TemporaryRepos
it 'searches with invalid regex' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=NSAttributedString%2BCCLFormat')
run_command('search', '--web', 'NSAttributedString+CCLFormat')
end
it 'should url encode search queries' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=NSAttributedString%2BCCLFormat')
run_command('search', '--web', 'NSAttributedString+CCLFormat')
end
it 'searches the web via the open! command' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=bananalib')
run_command('search', '--web', 'bananalib')
end
it 'includes option --osx correctly' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=on%3Aosx%20bananalib')
run_command('search', '--web', '--osx', 'bananalib')
end
it 'includes option --ios correctly' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=on%3Aios%20bananalib')
run_command('search', '--web', '--ios', 'bananalib')
end
it 'does not matter in which order the ios/osx options are set' do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=on%3Aosx%20on%3Aios%20bananalib')
run_command('search', '--web', '--ios', '--osx', 'bananalib')
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=on%3Aosx%20on%3Aios%20bananalib')
run_command('search', '--web', '--osx', '--ios', 'bananalib')
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment