Commit 9a41405d authored by AliSoftware's avatar AliSoftware

Merge pull request #2817 from CocoaPods/fix/Core-188

Fix Core#188 : pod search now uses plain-text + new optional `--regex` flag
parents bfbd6924 6e60718c
...@@ -58,6 +58,11 @@ Next: ...@@ -58,6 +58,11 @@ Next:
Metrics/ClassLength: Metrics/ClassLength:
Enabled: false Enabled: false
# Arbitrary max lengths for methods simply do not work and enabling this will
# lead to a never ending stream of annoyance and changes.
Metrics/MethodLength:
Enabled: false
# No enforced convention here. # No enforced convention here.
Metrics/BlockNesting: Metrics/BlockNesting:
Enabled: false Enabled: false
......
...@@ -41,11 +41,6 @@ Metrics/CyclomaticComplexity: ...@@ -41,11 +41,6 @@ Metrics/CyclomaticComplexity:
Metrics/LineLength: Metrics/LineLength:
Max: 1060 Max: 1060
# Offense count: 106
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 39
# Offense count: 12 # Offense count: 12
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Max: 10 Max: 10
......
...@@ -32,6 +32,16 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -32,6 +32,16 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
copying resources to main application bundle. copying resources to main application bundle.
[Yan Rabovik](https://github.com/rabovik) [Yan Rabovik](https://github.com/rabovik)
##### Enhancements
* `pod search`, `pod spec which`, `pod spec cat` and `pod spec edit`
now use plain text search by default instead of a regex. Especially
`pod search UIView+UI` now searches for pods containing exactly `UIView+UI`
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)
[Core#188](https://github.com/CocoaPods/Core/issues/188)
## 0.35.0.rc2 ## 0.35.0.rc2
......
...@@ -15,6 +15,7 @@ module Pod ...@@ -15,6 +15,7 @@ module Pod
def self.options def self.options
[ [
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, and description'], ['--full', 'Search by name, summary, and description'],
['--stats', 'Show additional stats (like GitHub watchers and forks)'], ['--stats', 'Show additional stats (like GitHub watchers and forks)'],
['--ios', 'Restricts the search to Pods supported on iOS'], ['--ios', 'Restricts the search to Pods supported on iOS'],
...@@ -24,6 +25,7 @@ module Pod ...@@ -24,6 +25,7 @@ module Pod
end end
def initialize(argv) def initialize(argv)
@use_regex = argv.flag?('regex')
@full_text_search = argv.flag?('full') @full_text_search = argv.flag?('full')
@stats = argv.flag?('stats') @stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios') @supported_on_ios = argv.flag?('ios')
...@@ -38,7 +40,7 @@ module Pod ...@@ -38,7 +40,7 @@ module Pod
super super
help! 'A search query is required.' unless @query help! 'A search query is required.' unless @query
unless @web unless @web || !@use_regex
begin begin
/#{@query.join(' ').strip}/ /#{@query.join(' ').strip}/
rescue RegexpError rescue RegexpError
...@@ -71,7 +73,10 @@ module Pod ...@@ -71,7 +73,10 @@ module Pod
end end
def local_search def local_search
sets = SourcesManager.search_by_name(@query.join(' ').strip, @full_text_search) query_regex = @query.join(' ').strip
query_regex = Regexp.escape(query_regex) unless @use_regex
sets = SourcesManager.search_by_name(query_regex, @full_text_search)
if @supported_on_ios if @supported_on_ios
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) } sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end end
......
...@@ -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,16 @@ module Pod ...@@ -310,6 +325,16 @@ 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)
/#{query}/
rescue RegexpError
help! 'A valid regular expression is required.'
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)
......
Pod::Spec.new do |s|
s.name = 'Pod+With+Plus+Signs'
s.version = '1.0'
s.authors = 'Evil Corp'
s.homepage = 'http://evil-corp.local/pod_with_plus_signs.html'
s.summary = 'Messing with special chars'
s.description = 'I love messing up with special chars in my pod name! Mouahahahahaa (evil laugh)'
s.platform = :ios
s.source = { :git => 'http://evil-corp.local/pod_with_plus_signs.git', :tag => '1.0' }
s.source_files = 'Classes/*.{h,m}'
s.license = {
:type => 'MIT',
:file => 'LICENSE',
:text => 'Permission is hereby granted ...'
}
end
...@@ -22,11 +22,14 @@ module Pod ...@@ -22,11 +22,14 @@ module Pod
jsonkit_set = sets.find { |s| s.name == 'JSONKit' } jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = { dates = {
'BananaLib' => Time.now, 'BananaLib' => Time.now,
'JSONKit' => Time.parse('01/01/1970') } 'JSONKit' => Time.parse('01/01/1970'),
'Pod+With+Plus+Signs' => Time.parse('01/01/1970'),
}
Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates) Specification::Set::Statistics.any_instance.stubs(:creation_dates).returns(dates)
out = run_command('list', 'new') out = run_command('list', 'new')
out.should.include('BananaLib') out.should.include('BananaLib')
out.should.not.include('JSONKit') out.should.not.include('JSONKit')
out.should.not.include('Pod+With+Plus+Signs')
end end
it 'presents the known pods with versions' do it 'presents the known pods with versions' do
......
...@@ -51,7 +51,24 @@ module Pod ...@@ -51,7 +51,24 @@ module Pod
end end
it 'shows a friendly message when locally searching with invalid regex' do it 'shows a friendly message when locally searching with invalid regex' do
lambda { run_command('search', '+') }.should.raise CLAide::Help lambda { run_command('search', '--regex', '+') }.should.raise CLAide::Help
end
it 'does not try to validate the query as a regex with plain-text search' do
lambda { run_command('search', '+') }.should.not.raise CLAide::Help
end
it 'uses regex search when asked for regex mode' do
output = run_command('search', '--regex', 'Ba(na)+Lib')
output.should.include? 'BananaLib'
output.should.not.include? 'Pod+With+Plus+Signs'
output.should.not.include? 'JSONKit'
end
it 'uses plain-text search when not asked for regex mode' do
output = run_command('search', 'Pod+With+Plus+Signs')
output.should.include? 'Pod+With+Plus+Signs'
output.should.not.include? 'BananaLib'
end end
describe 'option --web' do describe 'option --web' do
......
...@@ -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
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
......
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