Commit 77a563d9 authored by Olivier Halligon's avatar Olivier Halligon

Doc + --short option + preparing for `clean`

parent 6620fa90
......@@ -11,6 +11,30 @@ module Pod
or cleaning the pods cache.
DESC
def initialize(argv)
@cache_root = Config.instance.cache_root + 'Pods'
super
end
private
# @return [Hash<String, Hash<String, Request>>]
# A hash whose keys are the pod spec name
# And values are a hash keyed by the specs file paths
#
def cache_requests_per_pod
specs_dir = @cache_root + 'Specs'
spec_files = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
spec_files.reduce({}) do |hash, spec_file|
spec = Specification.from_file(spec_file)
hash[spec.name] = {} if hash[spec.name].nil?
release = spec_file.to_s.start_with? (specs_dir + 'Release').to_s
request = Downloader::Request.new(:spec => spec, :released => release)
hash[spec.name][spec_file] = request
hash
end
end
class List < Cache
self.summary = 'List the paths of pod caches for each known pod'
......@@ -23,21 +47,28 @@ module Pod
CLAide::Argument.new('NAME', false),
]
def self.options
[[
'--short', 'Only print the path relative to the cache root',
]].concat(super)
end
def initialize(argv)
@podname = argv.shift_argument
@cache_root = Config.instance.cache_root + 'Pods'
@short_output = argv.flag?('short')
super
end
def run
if (@podname.nil?)
cache_hash.each do |pod, list|
UI.puts("Cache root: #{@cache_root}") if @short_output
if (@podname.nil?) # Print all
cache_requests_per_pod.each do |pod, list|
UI.title pod
print_pod_cache_list(list)
end
else
cache_list = cache_hash[@podname]
else # Print only for the requested pod
cache_list = cache_requests_per_pod[@podname]
if cache_list.nil?
UI.notice("No cache for pod named #{@podname} found")
else
......@@ -48,28 +79,21 @@ module Pod
private
# Prints the list of specs & pod cache dirs for a single pod name
#
# @param [Hash<String,Request>] list
# The list of spec_file => Downloader::Request
# for a given pod name
#
def print_pod_cache_list(list)
list.each do |spec_file, request|
type = request.released_pod? ? 'Release' : 'External'
UI.section("#{request.spec.version} (#{type})") do
UI.labeled('Spec', spec_file)
UI.labeled('Pod', @cache_root+request.slug)
UI.labeled('Spec', @short_output ? spec_file.relative_path_from(@cache_root) : spec_file)
UI.labeled('Pod', @short_output ? request.slug : @cache_root+request.slug)
end
end
end
def cache_hash
specs_dir = @cache_root + 'Specs'
spec_files = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
spec_files.reduce({}) do |hash, spec_file|
spec = Specification.from_file(spec_file)
hash[spec.name] = {} if hash[spec.name].nil?
release = spec_file.to_s.start_with? (specs_dir + 'Release').to_s
request = Downloader::Request.new(:spec => spec, :released => release)
hash[spec.name][spec_file] = request
hash
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