-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,26 +13,37 @@ class Search < Command | |
CLAide::Argument.new('QUERY', true), | ||
] | ||
|
||
def self.all_platforms | ||
Specification::PLATFORMS.map do |platform| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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}"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description will no longer have the pretty name? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
There was a problem hiding this comment.
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
?