Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for tvOS and any possible future platforms. #14

Merged
merged 3 commits into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Master

##### Enhancements

* Add support for tvOS and any possible future platforms
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[#11](https://github.com/CocoaPods/cocoapods-search/issues/11)

* Perform regexp escape on individual query words before joining them
[Muhammed Yavuz Nuzumlalı](https://github.com/manuyavuz)
[#8](https://github.com/CocoaPods/cocoapods-search/issues/8)
Expand Down
47 changes: 25 additions & 22 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@ GEM
tzinfo (~> 1.1)
bacon (1.2.0)
claide (0.9.1)
cocoapods (0.38.2)
activesupport (>= 3.2.15)
cocoapods (0.39.0)
activesupport (>= 4.0.2)
claide (~> 0.9.1)
cocoapods-core (= 0.38.2)
cocoapods-downloader (~> 0.9.1)
cocoapods-core (= 0.39.0)
cocoapods-downloader (~> 0.9.3)
cocoapods-plugins (~> 0.4.2)
cocoapods-stats (~> 0.5.3)
cocoapods-trunk (~> 0.6.1)
cocoapods-try (~> 0.4.5)
cocoapods-search (~> 0.1.0)
cocoapods-stats (~> 0.6.2)
cocoapods-trunk (~> 0.6.4)
cocoapods-try (~> 0.5.1)
colored (~> 1.2)
escape (~> 0.0.4)
molinillo (~> 0.3.1)
nap (~> 0.8)
xcodeproj (~> 0.26.3)
cocoapods-core (0.38.2)
activesupport (>= 3.2.15)
molinillo (~> 0.4.0)
nap (~> 1.0)
xcodeproj (~> 0.28.2)
cocoapods-core (0.39.0)
activesupport (>= 4.0.2)
fuzzy_match (~> 2.0.4)
nap (~> 0.8.0)
cocoapods-downloader (0.9.1)
nap (~> 1.0)
cocoapods-downloader (0.9.3)
cocoapods-plugins (0.4.2)
nap
cocoapods-stats (0.5.3)
nap (~> 0.8)
cocoapods-trunk (0.6.1)
nap (>= 0.8)
cocoapods-stats (0.6.2)
cocoapods-trunk (0.6.4)
nap (>= 0.8, < 2.0)
netrc (= 0.7.8)
cocoapods-try (0.4.5)
cocoapods-try (0.5.1)
colored (1.2)
escape (0.0.4)
fuzzy_match (2.0.4)
Expand All @@ -52,16 +52,16 @@ GEM
metaclass (~> 0.0.1)
mocha-on-bacon (0.2.2)
mocha (>= 0.13.0)
molinillo (0.3.1)
nap (0.8.0)
molinillo (0.4.0)
nap (1.0.0)
netrc (0.7.8)
prettybacon (0.0.2)
bacon (~> 1.2)
rake (10.4.2)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (0.26.3)
xcodeproj (0.28.2)
activesupport (>= 3)
claide (~> 0.9.1)
colored (~> 1.2)
Expand All @@ -77,3 +77,6 @@ DEPENDENCIES
mocha-on-bacon
prettybacon
rake

BUNDLED WITH
1.10.6
51 changes: 28 additions & 23 deletions lib/cocoapods-search/command/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,37 @@ class Search < Command
CLAide::Argument.new('QUERY', true),
]

def self.all_platforms
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just define this as module_function?

Specification::PLATFORMS.map do |platform|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map(&:to_s)

platform.to_s
end
end

def all_platforms
self.class.all_platforms
end

def self.options
[
options = [
['--regex', 'Interpret the `QUERY` as a regular expression'],
['--full', 'Search by name, summary, description, and authors'],
['--stats', 'Show additional stats (like GitHub watchers and forks)'],
['--ios', 'Restricts the search to Pods supported on iOS'],
['--osx', 'Restricts the search to Pods supported on OS X'],
['--watchos', 'Restricts the search to Pods supported on Watch OS'],
['--web', 'Searches on cocoapods.org'],
].concat(super.reject { |option, _| option == '--silent' })
]
options += all_platforms.map do |platform|
["--#{platform}", "Restricts the search to Pods supported on #{platform}"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description will no longer have the pretty name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thougth about the same. Do you have any suggestions like adding a method to Specification which gives pretty names?

end
options.concat(super.reject { |option, _| option == '--silent' })
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')
@supported_on_osx = argv.flag?('osx')
@supported_on_watchos = argv.flag?('watchos')
@web = argv.flag?('web')
@platform_filters = all_platforms.map do |platform|
argv.flag?(platform) ? platform.to_sym : nil
end.compact
@query = argv.arguments! unless argv.arguments.empty?
config.silent = false
super
Expand Down Expand Up @@ -61,12 +72,11 @@ def run
end

def web_search
query_parameter = [
('on:osx' if @supported_on_osx),
('on:ios' if @supported_on_ios),
('on:watchos' if @supported_on_watchos),
@query,
].compact.flatten.join(' ')
queries = @platform_filters.map do |platform|
"on:#{platform}"
end
queries += @query
query_parameter = queries.compact.flatten.join(' ')
url = "https://cocoapods.org/?q=#{CGI.escape(query_parameter).gsub('+', '%20')}"
UI.puts("Opening #{url}")
open!(url)
Expand All @@ -78,17 +88,12 @@ def local_search
}.join(' ').strip

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
if @supported_on_osx
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:osx) }
end
if @supported_on_watchos
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(:watchos) }

@platform_filters.each do |platform|
sets.reject! { |set| !set.specification.available_platforms.map(&:name).include?(platform) }
end

sets.each do |set|
sets.each do |set|
begin
if @stats
UI.pod(set, :stats)
Expand Down
22 changes: 22 additions & 0 deletions spec/command/search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ module Pod
output.should.not.include? 'BananaLib'
end

it 'restricts the search to Pods supported on tvOS' do
output = run_command('search', '', '--tvos')
output.should.include? 'monkey'
output.should.not.include? 'BananaLib'
end

it 'outputs with the silent parameter' do
output = run_command('search', 'BananaLib', '--silent')
output.should.include? 'BananaLib'
Expand Down Expand Up @@ -115,6 +121,22 @@ module Pod
run_command('search', '--web', '--ios', 'bananalib')
end

it 'includes option --watchos correctly' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Awatchos%20bananalib')
run_command('search', '--web', '--watchos', 'bananalib')
end

it 'includes option --tvos correctly' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Atvos%20bananalib')
run_command('search', '--web', '--tvos', 'bananalib')
end

it 'includes any new platform option correctly' do
Command::Search.any_instance.stubs(:all_platforms).returns(%w(ios osx watchos tvos whateveros))
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Awhateveros%20bananalib')
run_command('search', '--web', '--whateveros', 'bananalib')
end

it 'does not matter in which order the ios/osx options are set' do
Command::Search.any_instance.expects(:open!).with('https://cocoapods.org/?q=on%3Aosx%20on%3Aios%20bananalib')
run_command('search', '--web', '--ios', '--osx', 'bananalib')
Expand Down