Commit 22518894 authored by Florian R. Hanke's avatar Florian R. Hanke

Merge pull request #1893 from CocoaPods/web_search_regex

Web search regex
parents 9c478fbe 9471d58c
...@@ -36,9 +36,13 @@ module Pod ...@@ -36,9 +36,13 @@ module Pod
super super
help! "A search query is required." unless @query help! "A search query is required." unless @query
/#{@query.join(' ').strip}/ unless @web
rescue RegexpError begin
help! "A valid regular expression is required." /#{@query.join(' ').strip}/
rescue RegexpError
help! "A valid regular expression is required."
end
end
end end
def run def run
...@@ -54,11 +58,11 @@ module Pod ...@@ -54,11 +58,11 @@ module Pod
def web_search def web_search
query_parameter = [ query_parameter = [
('on%3Aosx' if @supported_on_osx), ('on:osx' if @supported_on_osx),
('on%3Aios' if @supported_on_ios), ('on:ios' if @supported_on_ios),
@query @query
].compact.flatten.join('%20') ].compact.flatten.join(' ')
url = "http://cocoapods.org/?q=#{query_parameter}" url = "http://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub("+", "%20")}"
UI.puts("Opening #{url}") UI.puts("Opening #{url}")
open!(url) open!(url)
end end
......
...@@ -50,7 +50,7 @@ module Pod ...@@ -50,7 +50,7 @@ module Pod
output.should.include? 'BananaLib' output.should.include? 'BananaLib'
end end
it "shows a friendly message when 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', '+') }.should.raise CLAide::Help
end end
...@@ -58,6 +58,16 @@ module Pod ...@@ -58,6 +58,16 @@ module Pod
extend SpecHelper::TemporaryRepos 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 it "searches the web via the open! command" do
Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=bananalib') Command::Search.any_instance.expects(:open!).with('http://cocoapods.org/?q=bananalib')
run_command('search', '--web', 'bananalib') run_command('search', '--web', 'bananalib')
......
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