Commit 3a8cbe64 authored by Olivier Halligon's avatar Olivier Halligon Committed by Olivier Halligon

Fix for CocoaPods/Core#188

parent 3cbfa114
...@@ -15,6 +15,7 @@ module Pod ...@@ -15,6 +15,7 @@ module Pod
def self.options def self.options
[ [
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, and description'], ['--full', 'Search by name, summary, and description'],
['--stats', 'Show additional stats (like GitHub watchers and forks)'], ['--stats', 'Show additional stats (like GitHub watchers and forks)'],
['--ios', 'Restricts the search to Pods supported on iOS'], ['--ios', 'Restricts the search to Pods supported on iOS'],
...@@ -24,6 +25,7 @@ module Pod ...@@ -24,6 +25,7 @@ module Pod
end end
def initialize(argv) def initialize(argv)
@use_regex = argv.flag?('regex')
@full_text_search = argv.flag?('full') @full_text_search = argv.flag?('full')
@stats = argv.flag?('stats') @stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios') @supported_on_ios = argv.flag?('ios')
...@@ -38,7 +40,7 @@ module Pod ...@@ -38,7 +40,7 @@ module Pod
super super
help! 'A search query is required.' unless @query help! 'A search query is required.' unless @query
unless @web unless @web || !@use_regex
begin begin
/#{@query.join(' ').strip}/ /#{@query.join(' ').strip}/
rescue RegexpError rescue RegexpError
...@@ -71,7 +73,10 @@ module Pod ...@@ -71,7 +73,10 @@ module Pod
end end
def local_search def local_search
sets = SourcesManager.search_by_name(@query.join(' ').strip, @full_text_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 if @supported_on_ios
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) } sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end end
......
...@@ -337,7 +337,7 @@ module Pod ...@@ -337,7 +337,7 @@ module Pod
# @return [Pathname] the absolute path or paths of the given podspec # @return [Pathname] the absolute path or paths of the given podspec
# #
def get_path_of_spec(spec, show_all = false) def get_path_of_spec(spec, show_all = false)
sets = SourcesManager.search_by_name(spec) sets = SourcesManager.search_by_name(Regexp.escape(spec))
if sets.count == 1 if sets.count == 1
set = sets.first set = sets.first
......
Pod::Spec.new do |s|
s.name = 'Foo+Bar'
s.version = '1.0'
s.authors = 'FooBar Corp'
s.homepage = 'http://foobar-corp.local/foobar.html'
s.summary = 'Wohoo foobars!'
s.description = 'Silly foos, silly bars.'
s.platform = :ios
s.source = { :git => 'http://foobar-corp.local/foobar.git', :tag => '1.0' }
s.source_files = 'Classes/*.{h,m}'
s.license = {
:type => 'MIT',
:file => 'LICENSE',
:text => 'Permission is hereby granted ...'
}
end
...@@ -22,11 +22,14 @@ module Pod ...@@ -22,11 +22,14 @@ module Pod
jsonkit_set = sets.find { |s| s.name == 'JSONKit' } jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = { dates = {
'BananaLib' => Time.now, 'BananaLib' => Time.now,
'JSONKit' => Time.parse('01/01/1970') } 'JSONKit' => Time.parse('01/01/1970'),
'Foo+Bar' => Time.parse('01/01/1970'),
}
Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates) Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates)
out = run_command('list', 'new') out = run_command('list', 'new')
out.should.include('BananaLib') out.should.include('BananaLib')
out.should.not.include('JSONKit') out.should.not.include('JSONKit')
out.should.not.include('Foo+Bar')
end end
it 'presents the known pods with versions' do it 'presents the known pods with versions' do
......
...@@ -51,7 +51,18 @@ module Pod ...@@ -51,7 +51,18 @@ module Pod
end end
it 'shows a friendly message when locally searching with invalid regex' do it 'shows a friendly message when locally searching with invalid regex' do
lambda { run_command('search', '+') }.should.raise CLAide::Help lambda { run_command('search', '--regex', '+') }.should.raise CLAide::Help
end
it 'uses regex when asked for regex mode' do
output = run_command('search', '--regex', 'Ba(na)+Lib')
output.should.include? 'BananaLib'
end
it 'uses plain-text search when not asked for regex mode' do
output = run_command('search', 'Foo+Bar')
output.should.include? 'Foo+Bar'
output.should.not.include? 'BananaLib'
end end
describe 'option --web' do describe 'option --web' do
......
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