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:
Metrics/ClassLength:
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.
Metrics/BlockNesting:
Enabled: false
......
......@@ -41,11 +41,6 @@ Metrics/CyclomaticComplexity:
Metrics/LineLength:
Max: 1060
# Offense count: 106
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 39
# Offense count: 12
Metrics/PerceivedComplexity:
Max: 10
......
......@@ -32,6 +32,16 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
copying resources to main application bundle.
[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
......
......@@ -15,6 +15,7 @@ module Pod
def self.options
[
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, and description'],
['--stats', 'Show additional stats (like GitHub watchers and forks)'],
['--ios', 'Restricts the search to Pods supported on iOS'],
......@@ -24,6 +25,7 @@ module Pod
end
def initialize(argv)
@use_regex = argv.flag?('regex')
@full_text_search = argv.flag?('full')
@stats = argv.flag?('stats')
@supported_on_ios = argv.flag?('ios')
......@@ -38,7 +40,7 @@ module Pod
super
help! 'A search query is required.' unless @query
unless @web
unless @web || !@use_regex
begin
/#{@query.join(' ').strip}/
rescue RegexpError
......@@ -71,7 +73,10 @@ module Pod
end
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
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:ios) }
end
......
......@@ -152,33 +152,37 @@ module Pod
self.summary = 'Prints the path of the given spec.'
self.description = <<-DESC
Prints the path of 'NAME.podspec'
Prints the path of the .podspec file(s) whose name is matching `QUERY`
DESC
self.arguments = [
CLAide::Argument.new('NAME', false),
CLAide::Argument.new('QUERY', false),
]
def self.options
[
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--show-all', 'Print all versions of the given podspec'],
].concat(super)
end
def initialize(argv)
@use_regex = argv.flag?('regex')
@show_all = argv.flag?('show-all')
@spec = argv.shift_argument
@spec = @spec.gsub('.podspec', '') unless @spec.nil?
@query = argv.shift_argument
@query = @query.gsub('.podspec', '') unless @query.nil?
super
end
def validate!
super
help! 'A podspec name is required.' unless @spec
help! 'A podspec name is required.' unless @query
validate_regex!(@query) if @use_regex
end
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
......@@ -188,36 +192,42 @@ module Pod
self.summary = 'Prints a spec file.'
self.description = <<-DESC
Prints 'NAME.podspec' to standard output.
Prints the content of the podspec(s) whose name matches `QUERY` to standard output.
DESC
self.arguments = [
CLAide::Argument.new('NAME', false),
CLAide::Argument.new('QUERY', false),
]
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
def initialize(argv)
@use_regex = argv.flag?('regex')
@show_all = argv.flag?('show-all')
@spec = argv.shift_argument
@spec = @spec.gsub('.podspec', '') unless @spec.nil?
@query = argv.shift_argument
@query = @query.gsub('.podspec', '') unless @query.nil?
super
end
def validate!
super
help! 'A podspec name is required.' unless @spec
help! 'A podspec name is required.' unless @query
validate_regex!(@query) if @use_regex
end
def run
query = @use_regex ? @query : Regexp.escape(@query)
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 }]? ")
specs[index]
else
get_path_of_spec(@spec)
get_path_of_spec(query)
end
UI.puts File.read(filepath)
......@@ -230,38 +240,43 @@ module Pod
self.summary = 'Edit a spec file.'
self.description = <<-DESC
Opens 'NAME.podspec' to be edited.
Opens the podspec matching `QUERY` to be edited.
DESC
self.arguments = [
CLAide::Argument.new('NAME', false),
CLAide::Argument.new('QUERY', false),
]
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
def initialize(argv)
@use_regex = argv.flag?('regex')
@show_all = argv.flag?('show-all')
@spec = argv.shift_argument
@spec = @spec.gsub('.podspec', '') unless @spec.nil?
@query = argv.shift_argument
@query = @query.gsub('.podspec', '') unless @query.nil?
super
end
def validate!
super
help! 'A podspec name is required.' unless @spec
help! 'A podspec name is required.' unless @query
validate_regex!(@query) if @use_regex
end
def run
query = @use_regex ? @query : Regexp.escape(@query)
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}]? "
index = choose_from_array(specs, message)
filepath = specs[index]
else
filepath = get_path_of_spec(@spec)
filepath = get_path_of_spec(query)
end
exec_editor(filepath.to_s) if File.exist? filepath
......@@ -310,6 +325,16 @@ module Pod
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
#
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
jsonkit_set = sets.find { |s| s.name == 'JSONKit' }
dates = {
'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)
out = run_command('list', 'new')
out.should.include('BananaLib')
out.should.not.include('JSONKit')
out.should.not.include('Pod+With+Plus+Signs')
end
it 'presents the known pods with versions' do
......
......@@ -51,7 +51,24 @@ module Pod
end
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
describe 'option --web' do
......
......@@ -226,6 +226,53 @@ module Pod
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
it_should_check_for_existence('which')
it_should_check_for_ambiguity('which')
......@@ -235,6 +282,8 @@ module Pod
text = 'AFNetworking.podspec'
UI.output.should.include text.gsub(/\n/, '')
end
describe_regex_support('which')
end
#-------------------------------------------------------------------------#
......@@ -242,7 +291,7 @@ module Pod
describe Command::Spec::Cat do
it_should_check_for_existence('cat')
it_should_check_for_ambiguity('cat')
it 'cats the given podspec' do
lambda { command('spec', 'cat', 'AFNetworking').run }.should.not.raise
UI.output.should.include fixture('spec-repos/master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json').read
......@@ -253,6 +302,8 @@ module Pod
run_command('spec', 'cat', '--show-all', 'AFNetworking')
UI.output.should.include fixture('spec-repos/master/Specs/AFNetworking/2.4.1/AFNetworking.podspec.json').read
end
describe_regex_support('cat')
end
#-------------------------------------------------------------------------#
......@@ -268,7 +319,7 @@ module Pod
it_should_check_for_existence('edit')
it_should_check_for_ambiguity('edit')
it 'would execute the editor specified in ENV with the given podspec' do
ENV['EDITOR'] = 'podspeceditor'
lambda { command('spec', 'edit', 'AFNetworking').run }.should.raise SystemExit
......@@ -295,6 +346,8 @@ module Pod
lambda { command('spec', 'edit', 'AFNetworking').run }.should.raise Informative
File.unstub(:exists?)
end
describe_regex_support('edit', SystemExit) { ENV['EDITOR'] = 'podspeceditor' }
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