Commit 9a6268ff authored by Eloy Duran's avatar Eloy Duran

Add search command which finds pods who's name matches.

parent 43094e70
......@@ -2,6 +2,7 @@ module Pod
class Command
autoload :Install, 'cocoapods/command/install'
autoload :Repo, 'cocoapods/command/repo'
autoload :Search, 'cocoapods/command/search'
autoload :Setup, 'cocoapods/command/setup'
autoload :Spec, 'cocoapods/command/spec'
......@@ -33,6 +34,7 @@ module Pod
"To see help for the available commands run:\n" \
"\n" \
" * $ pod setup --help\n" \
" * $ pod search --help\n" \
" * $ pod install --help\n" \
" * $ pod repo --help"
end
......@@ -68,6 +70,7 @@ module Pod
command_class = case argv.shift_argument
when 'install' then Install
when 'repo' then Repo
when 'search' then Search
when 'setup' then Setup
when 'spec' then Spec
end
......
module Pod
class Command
class Search < Command
def initialize(argv)
unless @query = argv.arguments.first
super
end
end
def run
Source.search_by_name(@query.strip).each do |set|
puts "#{set.name} (#{set.versions.reverse.join(", ")})"
end
end
end
end
end
......@@ -16,6 +16,14 @@ module Pod
raise(Informative, "Unable to find a pod named `#{dependency.name}'")
end
def self.search_by_name(query)
result = all.map { |source| source.search_by_name(query) }.flatten
if result.empty?
raise(Informative, "Unable to find a pod who's name matches `#{query}'")
end
result
end
attr_reader :repo
def initialize(repo)
......@@ -27,5 +35,12 @@ module Pod
Specification::Set.by_pod_dir(dir)
end
end
def search_by_name(query)
dirs = @repo.children.select do |child|
child.basename.to_s.downcase.include?(query.downcase)
end
dirs.map { |dir| Specification::Set.by_pod_dir(dir) }
end
end
end
......@@ -37,4 +37,40 @@ describe "Pod::Command" do
(repo2.dir + 'README').read.should.include 'Added!'
(repo3.dir + 'README').read.should.include 'Added!'
end
before do
config.repos_dir = fixture('spec-repos')
end
after do
config.repos_dir = tmp_repos_path
end
it "searches for a pod who's name matches the given query ignoring case" do
[
[
' s ',
[
"ASIHTTPRequest (1.8, 1.8.1)",
"ASIWebPageRequest (1.8, 1.8.1)",
"JSONKit (1.4)",
"SSZipArchive (1.0)"
]
],
[
'json',
[
"JSONKit (1.4)"
]
]
].each do |query, result|
command = Pod::Command.parse('search', query)
def command.puts(msg)
(@printed ||= []) << msg
end
command.run
printed = command.instance_variable_get(:@printed)
printed.should == result.sort
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