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
f1f43240
Commit
f1f43240
authored
Nov 14, 2014
by
Olivier Halligon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Also added regex support to `pod spec which/cat/edit` for consistency.
parent
f2c15270
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
28 deletions
+110
-28
CHANGELOG.md
CHANGELOG.md
+6
-4
spec.rb
lib/cocoapods/command/spec.rb
+51
-24
spec_spec.rb
spec/functional/command/spec_spec.rb
+53
-0
No files found.
CHANGELOG.md
View file @
f1f43240
...
@@ -34,10 +34,12 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
...
@@ -34,10 +34,12 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Enhancements
##### Enhancements
*
`pod search`
now uses plain-text search by default instead of a regex,
*
`pod search`
,
`pod spec which`
,
`pod spec cat`
and
`pod spec edit`
allowing to run e.g.
`pod search UIView+`
to search for pods containing
now use plain text search by default instead of a regex. Especially
`UIView+`
in their name. You can still use a regular expression with the
`pod search UIView+UI`
now searches for pods containing exactly
`UIView+UI`
new
`--regex`
flag of the
`pod search`
command.
in their name, not trying to interpret the
`+`
as a regular expression.
_Note: You can still use a regular expression with the new
`--regex`
flag that has
been added to these commands, e.g.
`pod search --regex (NS|UI)Color`
._
[
Olivier Halligon
](
https://github.com/AliSoftware
)
[
Olivier Halligon
](
https://github.com/AliSoftware
)
[
Core#188
](
https://github.com/CocoaPods/Core/issues/188
)
[
Core#188
](
https://github.com/CocoaPods/Core/issues/188
)
...
...
lib/cocoapods/command/spec.rb
View file @
f1f43240
...
@@ -152,33 +152,37 @@ module Pod
...
@@ -152,33 +152,37 @@ module Pod
self
.
summary
=
'Prints the path of the given spec.'
self
.
summary
=
'Prints the path of the given spec.'
self
.
description
=
<<-
DESC
self
.
description
=
<<-
DESC
Prints the path of
'NAME.podspec'
Prints the path of
the .podspec file(s) whose name is matching `QUERY`
DESC
DESC
self
.
arguments
=
[
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'
NAME
'
,
false
),
CLAide
::
Argument
.
new
(
'
QUERY
'
,
false
),
]
]
def
self
.
options
def
self
.
options
[
[
[
'--regex'
,
'Interpret the `QUERY` as a regular expression'
],
[
'--show-all'
,
'Print all versions of the given podspec'
],
[
'--show-all'
,
'Print all versions of the given podspec'
],
].
concat
(
super
)
].
concat
(
super
)
end
end
def
initialize
(
argv
)
def
initialize
(
argv
)
@use_regex
=
argv
.
flag?
(
'regex'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@
spec
=
argv
.
shift_argument
@
query
=
argv
.
shift_argument
@
spec
=
@spec
.
gsub
(
'.podspec'
,
''
)
unless
@spec
.
nil?
@
query
=
@query
.
gsub
(
'.podspec'
,
''
)
unless
@query
.
nil?
super
super
end
end
def
validate!
def
validate!
super
super
help!
'A podspec name is required.'
unless
@spec
help!
'A podspec name is required.'
unless
@query
validate_regex!
(
@query
)
if
@use_regex
end
end
def
run
def
run
UI
.
puts
get_path_of_spec
(
@spec
,
@show_all
)
query
=
@use_regex
?
@query
:
Regexp
.
escape
(
@query
)
UI
.
puts
get_path_of_spec
(
query
,
@show_all
)
end
end
end
end
...
@@ -188,36 +192,42 @@ module Pod
...
@@ -188,36 +192,42 @@ module Pod
self
.
summary
=
'Prints a spec file.'
self
.
summary
=
'Prints a spec file.'
self
.
description
=
<<-
DESC
self
.
description
=
<<-
DESC
Prints
'NAME.podspec'
to standard output.
Prints
the content of the podspec(s) whose name matches `QUERY`
to standard output.
DESC
DESC
self
.
arguments
=
[
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'
NAME
'
,
false
),
CLAide
::
Argument
.
new
(
'
QUERY
'
,
false
),
]
]
def
self
.
options
def
self
.
options
[[
'--show-all'
,
'Pick from all versions of the given podspec'
]].
concat
(
super
)
[
[
'--regex'
,
'Interpret the `QUERY` as a regular expression'
],
[
'--show-all'
,
'Pick from all versions of the given podspec'
]
].
concat
(
super
)
end
end
def
initialize
(
argv
)
def
initialize
(
argv
)
@use_regex
=
argv
.
flag?
(
'regex'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@
spec
=
argv
.
shift_argument
@
query
=
argv
.
shift_argument
@
spec
=
@spec
.
gsub
(
'.podspec'
,
''
)
unless
@spec
.
nil?
@
query
=
@query
.
gsub
(
'.podspec'
,
''
)
unless
@query
.
nil?
super
super
end
end
def
validate!
def
validate!
super
super
help!
'A podspec name is required.'
unless
@spec
help!
'A podspec name is required.'
unless
@query
validate_regex!
(
@query
)
if
@use_regex
end
end
def
run
def
run
query
=
@use_regex
?
@query
:
Regexp
.
escape
(
@query
)
filepath
=
if
@show_all
filepath
=
if
@show_all
specs
=
get_path_of_spec
(
@spec
,
@show_all
).
split
(
/\n/
)
specs
=
get_path_of_spec
(
query
,
@show_all
).
split
(
/\n/
)
index
=
choose_from_array
(
specs
,
"Which spec would you like to print [1-
#{
specs
.
count
}
]? "
)
index
=
choose_from_array
(
specs
,
"Which spec would you like to print [1-
#{
specs
.
count
}
]? "
)
specs
[
index
]
specs
[
index
]
else
else
get_path_of_spec
(
@spec
)
get_path_of_spec
(
query
)
end
end
UI
.
puts
File
.
read
(
filepath
)
UI
.
puts
File
.
read
(
filepath
)
...
@@ -230,38 +240,43 @@ module Pod
...
@@ -230,38 +240,43 @@ module Pod
self
.
summary
=
'Edit a spec file.'
self
.
summary
=
'Edit a spec file.'
self
.
description
=
<<-
DESC
self
.
description
=
<<-
DESC
Opens
'NAME.podspec'
to be edited.
Opens
the podspec matching `QUERY`
to be edited.
DESC
DESC
self
.
arguments
=
[
self
.
arguments
=
[
CLAide
::
Argument
.
new
(
'
NAME
'
,
false
),
CLAide
::
Argument
.
new
(
'
QUERY
'
,
false
),
]
]
def
self
.
options
def
self
.
options
[[
'--show-all'
,
'Pick which spec to edit from all available'
\
[
'versions of the given podspec'
]].
concat
(
super
)
[
'--regex'
,
'Interpret the `QUERY` as a regular expression'
],
[
'--show-all'
,
'Pick from all versions of the given podspec'
]
].
concat
(
super
)
end
end
def
initialize
(
argv
)
def
initialize
(
argv
)
@use_regex
=
argv
.
flag?
(
'regex'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@show_all
=
argv
.
flag?
(
'show-all'
)
@
spec
=
argv
.
shift_argument
@
query
=
argv
.
shift_argument
@
spec
=
@spec
.
gsub
(
'.podspec'
,
''
)
unless
@spec
.
nil?
@
query
=
@query
.
gsub
(
'.podspec'
,
''
)
unless
@query
.
nil?
super
super
end
end
def
validate!
def
validate!
super
super
help!
'A podspec name is required.'
unless
@spec
help!
'A podspec name is required.'
unless
@query
validate_regex!
(
@query
)
if
@use_regex
end
end
def
run
def
run
query
=
@use_regex
?
@query
:
Regexp
.
escape
(
@query
)
if
@show_all
if
@show_all
specs
=
get_path_of_spec
(
@spec
,
@show_all
).
split
(
/\n/
)
specs
=
get_path_of_spec
(
query
,
@show_all
).
split
(
/\n/
)
message
=
"Which spec would you like to edit [1-
#{
specs
.
count
}
]? "
message
=
"Which spec would you like to edit [1-
#{
specs
.
count
}
]? "
index
=
choose_from_array
(
specs
,
message
)
index
=
choose_from_array
(
specs
,
message
)
filepath
=
specs
[
index
]
filepath
=
specs
[
index
]
else
else
filepath
=
get_path_of_spec
(
@spec
)
filepath
=
get_path_of_spec
(
query
)
end
end
exec_editor
(
filepath
.
to_s
)
if
File
.
exist?
filepath
exec_editor
(
filepath
.
to_s
)
if
File
.
exist?
filepath
...
@@ -310,6 +325,18 @@ module Pod
...
@@ -310,6 +325,18 @@ module Pod
private
private
# @param [String] query the regular expression string to validate
#
# @raise if the query is not a valid regular expression
#
def
validate_regex!
(
query
)
begin
/
#{
query
}
/
rescue
RegexpError
help!
'A valid regular expression is required.'
end
end
# @return [Fixnum] the index of the chosen array item
# @return [Fixnum] the index of the chosen array item
#
#
def
choose_from_array
(
array
,
message
)
def
choose_from_array
(
array
,
message
)
...
@@ -337,7 +364,7 @@ module Pod
...
@@ -337,7 +364,7 @@ module Pod
# @return [Pathname] the absolute path or paths of the given podspec
# @return [Pathname] the absolute path or paths of the given podspec
#
#
def
get_path_of_spec
(
spec
,
show_all
=
false
)
def
get_path_of_spec
(
spec
,
show_all
=
false
)
sets
=
SourcesManager
.
search_by_name
(
Regexp
.
escape
(
spec
)
)
sets
=
SourcesManager
.
search_by_name
(
spec
)
if
sets
.
count
==
1
if
sets
.
count
==
1
set
=
sets
.
first
set
=
sets
.
first
...
...
spec/functional/command/spec_spec.rb
View file @
f1f43240
...
@@ -226,6 +226,53 @@ module Pod
...
@@ -226,6 +226,53 @@ module Pod
end
end
end
end
def
describe_regex_support
(
command
,
raise_class
=
nil
)
describe
'RegEx support'
do
before
do
@test_source
=
Source
.
new
(
fixture
(
'spec-repos/test_repo'
))
Source
::
Aggregate
.
any_instance
.
stubs
(
:sources
).
returns
([
@test_source
])
SourcesManager
.
updated_search_index
=
nil
yield
if
block_given?
end
it
'raise when using an invalid regex'
do
lambda
{
run_command
(
'spec'
,
command
,
'--regex'
,
'+'
)
}.
should
.
raise
CLAide
::
Help
end
it
'does not try to validate the query as a regex with plain-text mode'
do
l
=
lambda
{
run_command
(
'spec'
,
command
,
'+'
)
}
if
raise_class
l
.
should
.
raise
raise_class
else
l
.
should
.
not
.
raise
CLAide
::
Help
end
end
it
'uses regex search when asked for regex mode'
do
l
=
lambda
{
run_command
(
'spec'
,
command
,
'--regex'
,
'Ba(na)+Lib'
)
}
if
raise_class
l
.
should
.
raise
raise_class
else
l
.
should
.
not
.
raise
end
UI
.
output
.
should
.
include?
'BananaLib'
UI
.
output
.
should
.
not
.
include?
'Pod+With+Plus+Signs'
UI
.
output
.
should
.
not
.
include?
'JSONKit'
end
it
'uses plain-text search when not asked for regex mode'
do
l
=
lambda
{
run_command
(
'spec'
,
command
,
'Pod+With+Plus+Signs'
)
}
if
raise_class
l
.
should
.
raise
raise_class
else
l
.
should
.
not
.
raise
end
UI
.
output
.
should
.
include?
'Pod+With+Plus+Signs'
UI
.
output
.
should
.
not
.
include?
'BananaLib'
end
end
end
describe
Command
::
Spec
::
Which
do
describe
Command
::
Spec
::
Which
do
it_should_check_for_existence
(
'which'
)
it_should_check_for_existence
(
'which'
)
it_should_check_for_ambiguity
(
'which'
)
it_should_check_for_ambiguity
(
'which'
)
...
@@ -235,6 +282,8 @@ module Pod
...
@@ -235,6 +282,8 @@ module Pod
text
=
'AFNetworking.podspec'
text
=
'AFNetworking.podspec'
UI
.
output
.
should
.
include
text
.
gsub
(
/\n/
,
''
)
UI
.
output
.
should
.
include
text
.
gsub
(
/\n/
,
''
)
end
end
describe_regex_support
(
'which'
)
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
@@ -253,6 +302,8 @@ module Pod
...
@@ -253,6 +302,8 @@ module Pod
run_command
(
'spec'
,
'cat'
,
'--show-all'
,
'AFNetworking'
)
run_command
(
'spec'
,
'cat'
,
'--show-all'
,
'AFNetworking'
)
UI
.
output
.
should
.
include
fixture
(
'spec-repos/master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json'
).
read
UI
.
output
.
should
.
include
fixture
(
'spec-repos/master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json'
).
read
end
end
describe_regex_support
(
'cat'
)
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
@@ -295,6 +346,8 @@ module Pod
...
@@ -295,6 +346,8 @@ module Pod
lambda
{
command
(
'spec'
,
'edit'
,
'AFNetworking'
).
run
}.
should
.
raise
Informative
lambda
{
command
(
'spec'
,
'edit'
,
'AFNetworking'
).
run
}.
should
.
raise
Informative
File
.
unstub
(
:exists?
)
File
.
unstub
(
:exists?
)
end
end
describe_regex_support
(
'edit'
,
SystemExit
)
{
ENV
[
'EDITOR'
]
=
'podspeceditor'
}
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