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

Implement --web search command option (see #1682). Add specs for the --web search option.

parent 5f506b49
......@@ -39,6 +39,17 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
test doesn't affect the normal workflow.
[Fabio Pelosin](https://github.com/irrationalfab)
* The `pod search <query>` command now supports searching on cocoapods.org
when searching using the option `--web`. Options `--ios` and `--osx` are
fully supported.
[Florian Hanke](https://github.com/floere)
[#1643][https://github.com/CocoaPods/CocoaPods/pull/1682]
* The `pod search <query>` command now supports multiword queries when using
the `--web` option.
[Florian Hanke](https://github.com/floere)
[#1643][https://github.com/CocoaPods/CocoaPods/pull/1682]
###### Refactor
* The command `podfile_info` is now a plugin offered by CocoaPods.
......
......@@ -16,7 +16,8 @@ module Pod
["--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"]
["--osx", "Restricts the search to Pods supported on OS X"],
["--web", "Searches on cocoapods.org"]
].concat(super.reject { |option, _| option == '--silent' })
end
......@@ -25,7 +26,8 @@ module Pod
@stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios')
@supported_on_osx = argv.flag?('osx')
@query = argv.shift_argument
@web = argv.flag?('web')
@query = argv.arguments! unless argv.arguments.empty?
config.silent = false
super
end
......@@ -36,7 +38,29 @@ module Pod
end
def run
sets = SourcesManager.search_by_name(@query.strip, @full_text_search)
if @web
web_search
else
local_search
end
end
extend Executable
executable :open
def web_search
query_parameter = [
('on%3Aosx' if @supported_on_osx),
('on%3Aios' if @supported_on_ios),
@query
].compact.flatten.join('%20')
url = "http://cocoapods.org/?q=#{query_parameter}"
UI.puts("Opening #{url}")
open!(url)
end
def local_search
sets = SourcesManager.search_by_name(@query.join(' ').strip, @full_text_search)
if @supported_on_ios
sets.reject!{ |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end
......@@ -57,6 +81,7 @@ module Pod
end
end
end
end
end
end
......@@ -18,7 +18,6 @@ module Pod
it "complains for wrong parameters" do
lambda { run_command('search') }.should.raise CLAide::Help
lambda { run_command('search', 'too', 'many') }.should.raise CLAide::Help
lambda { run_command('search', 'too', '--wrong') }.should.raise CLAide::Help
lambda { run_command('search', '--wrong') }.should.raise CLAide::Help
end
......@@ -50,5 +49,35 @@ module Pod
output = run_command('search', 'BananaLib', '--silent')
output.should.include? 'BananaLib'
end
describe "option --web" do
extend SpecHelper::TemporaryRepos
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