Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
d2744135
Commit
d2744135
authored
May 15, 2015
by
Olivier Halligon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Splitting `pod cache` subcommands in separate files
parent
d78f5894
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
160 additions
and
143 deletions
+160
-143
cache.rb
lib/cocoapods/command/cache.rb
+4
-143
clean.rb
lib/cocoapods/command/cache/clean.rb
+89
-0
list.rb
lib/cocoapods/command/cache/list.rb
+67
-0
No files found.
lib/cocoapods/command/cache.rb
View file @
d2744135
require
'cocoapods/downloader'
require
'cocoapods/command/cache/list'
require
'cocoapods/command/cache/clean'
module
Pod
class
Command
...
...
@@ -27,6 +29,8 @@ module Pod
# :release : boolean to tell if that's a release pod
# :slug : the slug path where the pod cache is located
#
# @todo Move this to Pod::Downloader::Cache
#
def
cache_info_per_pod
specs_dir
=
@cache_root
+
'Specs'
spec_files
=
specs_dir
.
find
.
select
{
|
f
|
f
.
fnmatch
(
'*.podspec.json'
)
}
...
...
@@ -48,149 +52,6 @@ module Pod
def
pod_type
(
pod_cache_info
)
pod_cache_info
[
:release
]
?
'Release'
:
'External'
end
class
List
<
Cache
self
.
summary
=
'List the paths of pod caches for each known pod'
self
.
description
=
<<-
DESC
Shows the content of cache organized by pod.
If `NAME` is given, show the results only for that pod name.
DESC
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'NAME'
,
false
),
]
def
self
.
options
[[
'--short'
,
'Only print the path relative to the cache root'
]].
concat
(
super
)
end
def
initialize
(
argv
)
@pod_name
=
argv
.
shift_argument
@short_output
=
argv
.
flag?
(
'short'
)
super
end
def
run
UI
.
puts
(
"Cache root:
#{
@cache_root
}
"
)
if
@short_output
if
@pod_name
.
nil?
# Print all
cache_info_per_pod
.
each
do
|
pod
,
infos
|
UI
.
title
pod
print_pod_cache_infos
(
infos
)
end
else
# Print only for the requested pod
cache_infos
=
cache_info_per_pod
[
@pod_name
]
if
cache_infos
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@pod_name
}
found"
)
else
print_pod_cache_infos
(
cache_infos
)
end
end
end
private
# Prints the list of specs & pod cache dirs for a single pod name
#
# @param [Array<Hash>] info_list
# The various infos about a pod cache. Keys are
# :spec_file, :version, :release and :slug
#
def
print_pod_cache_infos
(
info_list
)
info_list
.
each
do
|
info
|
UI
.
section
(
"
#{
info
[
:version
]
}
(
#{
pod_type
(
info
)
}
)"
)
do
if
@short_output
[
:spec_file
,
:slug
].
each
{
|
k
|
info
[
k
]
=
info
[
k
].
relative_path_from
(
@cache_root
)
}
end
UI
.
labeled
(
'Spec'
,
info
[
:spec_file
])
UI
.
labeled
(
'Pod'
,
info
[
:slug
])
end
end
end
end
class
Clean
<
Cache
self
.
summary
=
'Remove the cache for pods'
self
.
description
=
<<-
DESC
Remove the cache for a given pod, or clear the cache completely.
If there is multiple cache for various versions of the requested pod,
you will be asked which one to clean. Use `--all` to clean them all.
If you don't give a pod `NAME`, you need to specify the `--all`
flag (this is to avoid cleaning all the cache by mistake).
DESC
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'NAME'
,
false
),
]
def
self
.
options
[[
'--all'
,
'Remove all the cached pods without asking'
]].
concat
(
super
)
end
def
initialize
(
argv
)
@pod_name
=
argv
.
shift_argument
@wipe_all
=
argv
.
flag?
(
'all'
)
super
end
def
run
if
@pod_name
.
nil?
# && @wipe_all
# Remove all
clear_cache
else
# Remove only cache for this pod
cache_list
=
cache_info_per_pod
[
@pod_name
]
if
cache_list
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@pod_name
}
found"
)
elsif
cache_list
.
count
>
1
&&
!
@wipe_all
# Ask which to remove
choices
=
cache_list
.
map
{
|
c
|
"
#{
@pod_name
}
v
#{
c
[
:version
]
}
(
#{
pod_type
(
c
)
}
)"
}
index
=
UI
.
choose_from_array
(
choices
,
'Which pod cache do you want to remove?'
)
remove_caches
([
cache_list
[
index
]])
else
# Remove all found cache of this pod
remove_caches
(
cache_list
)
end
end
end
def
validate!
super
if
@pod_name
.
nil?
&&
!
@wipe_all
# Security measure, to avoid removing the pod cache too agressively by mistake
help!
'You should either specify a pod name or use the --all flag'
end
end
private
# Removes the specified cache
#
# @param [Array<Hash>] cache_infos
# An array of caches to remove, each specified with the same
# hash as cache_info_per_pod especially :spec_file and :slug
#
def
remove_caches
(
cache_infos
)
cache_infos
.
each
do
|
info
|
UI
.
message
(
"Removing spec
#{
info
[
:spec_file
]
}
(v
#{
info
[
:version
]
}
)"
)
FileUtils
.
rm
(
info
[
:spec_file
])
UI
.
message
(
"Removing cache
#{
info
[
:slug
]
}
"
)
FileUtils
.
rm_rf
(
info
[
:slug
])
end
end
def
clear_cache
UI
.
message
(
"Removing the whole cache dir
#{
@cache_root
}
"
)
FileUtils
.
rm_rf
(
@cache_root
)
end
end
end
end
end
lib/cocoapods/command/cache/clean.rb
0 → 100644
View file @
d2744135
module
Pod
class
Command
class
Cache
<
Command
class
Clean
<
Cache
self
.
summary
=
'Remove the cache for pods'
self
.
description
=
<<-
DESC
Remove the cache for a given pod, or clear the cache completely.
If there is multiple cache for various versions of the requested pod,
you will be asked which one to clean. Use `--all` to clean them all.
If you don't give a pod `NAME`, you need to specify the `--all`
flag (this is to avoid cleaning all the cache by mistake).
DESC
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'NAME'
,
false
),
]
def
self
.
options
[[
'--all'
,
'Remove all the cached pods without asking'
]].
concat
(
super
)
end
def
initialize
(
argv
)
@pod_name
=
argv
.
shift_argument
@wipe_all
=
argv
.
flag?
(
'all'
)
super
end
def
run
if
@pod_name
.
nil?
# && @wipe_all
# Remove all
clear_cache
else
# Remove only cache for this pod
cache_list
=
cache_info_per_pod
[
@pod_name
]
if
cache_list
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@pod_name
}
found"
)
elsif
cache_list
.
count
>
1
&&
!
@wipe_all
# Ask which to remove
choices
=
cache_list
.
map
{
|
c
|
"
#{
@pod_name
}
v
#{
c
[
:version
]
}
(
#{
pod_type
(
c
)
}
)"
}
index
=
UI
.
choose_from_array
(
choices
,
'Which pod cache do you want to remove?'
)
remove_caches
([
cache_list
[
index
]])
else
# Remove all found cache of this pod
remove_caches
(
cache_list
)
end
end
end
def
validate!
super
if
@pod_name
.
nil?
&&
!
@wipe_all
# Security measure, to avoid removing the pod cache too agressively by mistake
help!
'You should either specify a pod name or use the --all flag'
end
end
private
# Removes the specified cache
#
# @param [Array<Hash>] cache_infos
# An array of caches to remove, each specified with the same
# hash as cache_info_per_pod especially :spec_file and :slug
#
def
remove_caches
(
cache_infos
)
cache_infos
.
each
do
|
info
|
UI
.
message
(
"Removing spec
#{
info
[
:spec_file
]
}
(v
#{
info
[
:version
]
}
)"
)
do
FileUtils
.
rm
(
info
[
:spec_file
])
end
UI
.
message
(
"Removing cache
#{
info
[
:slug
]
}
"
)
do
FileUtils
.
rm_rf
(
info
[
:slug
])
end
end
end
def
clear_cache
UI
.
message
(
"Removing the whole cache dir
#{
@cache_root
}
"
)
do
FileUtils
.
rm_rf
(
@cache_root
)
end
end
end
end
end
end
lib/cocoapods/command/cache/list.rb
0 → 100644
View file @
d2744135
module
Pod
class
Command
class
Cache
<
Command
class
List
<
Cache
self
.
summary
=
'List the paths of pod caches for each known pod'
self
.
description
=
<<-
DESC
Shows the content of cache organized by pod.
If `NAME` is given, show the results only for that pod name.
DESC
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'NAME'
,
false
),
]
def
self
.
options
[[
'--short'
,
'Only print the path relative to the cache root'
]].
concat
(
super
)
end
def
initialize
(
argv
)
@pod_name
=
argv
.
shift_argument
@short_output
=
argv
.
flag?
(
'short'
)
super
end
def
run
UI
.
puts
(
"Cache root:
#{
@cache_root
}
"
)
if
@short_output
if
@pod_name
.
nil?
# Print all
cache_info_per_pod
.
each
do
|
pod
,
infos
|
UI
.
title
pod
print_pod_cache_infos
(
infos
)
end
else
# Print only for the requested pod
cache_infos
=
cache_info_per_pod
[
@pod_name
]
if
cache_infos
.
nil?
UI
.
notice
(
"No cache for pod named
#{
@pod_name
}
found"
)
else
print_pod_cache_infos
(
cache_infos
)
end
end
end
private
# Prints the list of specs & pod cache dirs for a single pod name
#
# @param [Array<Hash>] info_list
# The various infos about a pod cache. Keys are
# :spec_file, :version, :release and :slug
#
def
print_pod_cache_infos
(
info_list
)
info_list
.
each
do
|
info
|
UI
.
section
(
"
#{
info
[
:version
]
}
(
#{
pod_type
(
info
)
}
)"
)
do
if
@short_output
[
:spec_file
,
:slug
].
each
{
|
k
|
info
[
k
]
=
info
[
k
].
relative_path_from
(
@cache_root
)
}
end
UI
.
labeled
(
'Spec'
,
info
[
:spec_file
])
UI
.
labeled
(
'Pod'
,
info
[
:slug
])
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment