Commit 5f8ba914 authored by Fabio Pelosin's avatar Fabio Pelosin

[#188] Further cleanup

parent e7453f1d
module Pod module Pod
class Command class Command
class List < Command class List < Command
include DisplayPods
def self.banner def self.banner
%{List all pods: %{List all pods:
$ pod list $ pod list
...@@ -20,35 +18,33 @@ module Pod ...@@ -20,35 +18,33 @@ module Pod
super super
end end
include DisplayPods
extend Executable
executable :git
def initialize(argv) def initialize(argv)
@stats = argv.option('--stats') @stats = argv.option('--stats')
#TODO: accept only integers
@days = argv.arguments.first @days = argv.arguments.first
end end
def list_all
display_pod_list(all_pods_sets, @stats)
end
def dir def dir
File.expand_path '~/.cocoapods/master' File.expand_path '~/.cocoapods/master'
end end
def list_directory_at_commit(commit) def list_directory_at_commit(commit)
Dir.chdir(dir) do |_| Dir.chdir(dir) { git("ls-tree --name-only -r #{commit}") }
`git ls-tree --name-only -r #{commit}`
end
end end
def commit_at_days_ago (days) def commit_at_days_ago (days)
return 'HEAD' if days == 0 return 'HEAD' if days == 0
Dir.chdir(dir) do |_| Dir.chdir(dir) { git("rev-list -n1 --before=\"#{days} day ago\" master") }
`git rev-list -n1 --before="#{days} day ago" master`
end
end end
def pods_at_days_ago (days = 7) def pods_at_days_ago (days)
commit = commit_at_days_ago(days) commit = commit_at_days_ago(days)
dir_list = list_directory_at_commit(commit) dir_list = list_directory_at_commit(commit)
# Keep only directories # Keep only directories
dir_list.gsub!(/^[^\/]*$/,'') dir_list.gsub!(/^[^\/]*$/,'')
#Clean pod names #Clean pod names
...@@ -70,22 +66,27 @@ module Pod ...@@ -70,22 +66,27 @@ module Pod
end end
def list_new def list_new
#TODO: find the changes of all repos
pods_past = pods_at_days_ago(@days) pods_past = pods_at_days_ago(@days)
pods_now = pods_at_days_ago(0) pods_now = pods_at_days_ago(0)
pods_diff = pods_now - pods_past pods_diff = pods_now - pods_past
sets = all_pods_sets.select {|set| pods_diff.include?(set.name) } sets = all_pods_sets.select {|set| pods_diff.include?(set.name) }
puts puts
if pods_diff.count if sets.count != 0
puts "#{pods_diff.count} new pods were added in the last #{@days} days\n" puts "#{sets.count} new pods were added in the last #{@days} days"
puts puts
display_pod_list(sets, @stats) display_pod_list(sets, @stats)
else else
puts "No new pods".red puts "No new pods were added in the last #{@days} days"
end end
puts puts
end end
def list_all
display_pod_list(all_pods_sets, @stats)
end
def run def run
if @days if @days
list_new list_new
......
module Pod module Pod
class Command class Command
class Search < Command class Search < Command
include DisplayPods
def self.banner def self.banner
%{Search pods: %{Search pods:
$ pod search [QUERY] $ pod search [QUERY]
...@@ -19,6 +17,8 @@ module Pod ...@@ -19,6 +17,8 @@ module Pod
super super
end end
include DisplayPods
def initialize(argv) def initialize(argv)
@stats = argv.option('--stats') @stats = argv.option('--stats')
@full_text_search = argv.option('--full') @full_text_search = argv.option('--full')
......
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