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
9a6268ff
Commit
9a6268ff
authored
Sep 17, 2011
by
Eloy Duran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add search command which finds pods who's name matches.
parent
43094e70
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
0 deletions
+71
-0
command.rb
lib/cocoapods/command.rb
+3
-0
search.rb
lib/cocoapods/command/search.rb
+17
-0
source.rb
lib/cocoapods/source.rb
+15
-0
command_spec.rb
spec/functional/command_spec.rb
+36
-0
No files found.
lib/cocoapods/command.rb
View file @
9a6268ff
...
...
@@ -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
...
...
lib/cocoapods/command/search.rb
0 → 100644
View file @
9a6268ff
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
lib/cocoapods/source.rb
View file @
9a6268ff
...
...
@@ -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
spec/functional/command_spec.rb
View file @
9a6268ff
...
...
@@ -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
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