Commit 838ae0b5 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge pull request #185 from CocoaPods/improved-search

Improved search
parents 18bc2ab8 5bf9aa05
...@@ -2,7 +2,7 @@ module Pod ...@@ -2,7 +2,7 @@ module Pod
class Command class Command
class Search < Command class Search < Command
def self.banner def self.banner
%{Search pods: %{Search pods:
$ pod search [QUERY] $ pod search [QUERY]
...@@ -12,11 +12,13 @@ module Pod ...@@ -12,11 +12,13 @@ module Pod
end end
def self.options def self.options
" --stats Show additional stats (like GitHub watchers and forks)\n" +
" --full Search by name, summary, and description\n" + " --full Search by name, summary, and description\n" +
super super
end end
def initialize(argv) def initialize(argv)
@stats = argv.option('--stats')
@full_text_search = argv.option('--full') @full_text_search = argv.option('--full')
unless @query = argv.arguments.first unless @query = argv.arguments.first
super super
...@@ -25,18 +27,43 @@ module Pod ...@@ -25,18 +27,43 @@ module Pod
def run def run
Source.search_by_name(@query.strip, @full_text_search).each do |set| Source.search_by_name(@query.strip, @full_text_search).each do |set|
puts "==> #{set.name} (#{set.versions.reverse.join(", ")})" puts "\e[32m--> #{set.name} (#{set.versions.reverse.join(", ")})\e[0m"
puts " #{set.specification.summary.strip}"
puts " Homepage: #{set.specification.homepage}" puts_wrapped_text(set.specification.summary)
puts_detail('Homepage', set.specification.homepage)
source = set.specification.source.values[0]
puts_detail('Source', source)
puts_github_info(source) if @stats
source = set.specification.source
if source
url = source[:git] || source[:hg] || source[:svn] || source[:local]
puts " Source: #{url}" if url
end
puts puts
end end
end end
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
def puts_wrapped_text(txt, col = 80, indentation = 4)
indent = ' ' * indentation
puts txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n")
end
def puts_detail(title,string)
return if !string
# 8 is the length of homepage which might be displayed alone
number_of_spaces = ((8 - title.length) > 0) ? (8 - title.length) : 0
spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}"
end
def puts_github_info(url)
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
if original_url
repo_info = `curl -s -m 2 http://github.com/api/v2/json/repos/show/#{username}/#{reponame}`
watchers = repo_info.match(/\"watchers\"\W*:\W*([0-9]+)/).to_a[1]
forks = repo_info.match(/\"forks\"\W*:\W*([0-9]+)/).to_a[1]
puts_detail('Watchers', watchers)
puts_detail('Forks', forks)
end
end
end end
end end
end end
...@@ -64,7 +64,7 @@ module Pod ...@@ -64,7 +64,7 @@ module Pod
end end
def tarball_url_for(id) def tarball_url_for(id)
original_url, username, reponame = *(url.match(/[:\/](\w+)\/(\w+).git/).to_a) original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
"https://github.com/#{username}/#{reponame}/tarball/#{id}" "https://github.com/#{username}/#{reponame}/tarball/#{id}"
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