lib/pod/command/browser.rb in cocoapods-browser-0.0.3 vs lib/pod/command/browser.rb in cocoapods-browser-0.0.4
- old
+ new
@@ -2,63 +2,71 @@
class Command
class Browser < Command
self.summary = 'Open the homepage'
self.description = <<-DESC
- Opens the homepage on browser.
+ Opens the homepage of a pod in the browser.
DESC
- self.arguments = '[QUERY]'
+ self.arguments = '[NAME]'
def self.options
[
- '--spec', 'Open the podspec on the browser. github.com/tree/master/[PODNAME].podspec',
+ [ '--spec', 'Open the podspec in the browser. github.com/tree/master/[NAME].podspec' ],
].concat(super)
end
def initialize(argv)
@spec = argv.flag?('spec')
- @query = argv.arguments! unless argv.arguments.empty?
+ @names = argv.arguments! unless argv.arguments.empty?
super
end
def validate!
super
- help! "A search query is required." unless @query
+ help! 'A Pod name is required' unless @names
end
extend Executable
executable :open
def run
- @query.each do |query|
- opened = false
- sets = SourcesManager.search_by_name(query.strip, false)
- statistics_provider = Config.instance.spec_statistics_provider
- sets.each do |set|
- begin
- pod = Specification::Set::Presenter.new(set, statistics_provider)
- next if query != pod.name
-
- if url = pod.homepage
- if @spec && url =~ %r|^https?://github.com/|
- url << "/tree/master/#{pod.name}.podspec"
- else
- UI.warn "Skipping `#{pod.name}` because the homgepage is only `github.com`."
- next
- end
- UI.puts("Opening #{url}")
- open!(url)
- opened = true
- else
- UI.warn "Skipping `#{pod.name}` because the homepage not found."
- end
- rescue DSLError
- UI.warn "Skipping `#{pod.name}` because the podspec contains errors."
+# update_specs_repos
+ @names.each do |name|
+ if spec = spec_with_name(name)
+ UI.title "Opening #{spec.name}" do
+ url = pick_open_url(spec)
+ UI.puts(">>> #{url}")
+ open!(url)
end
end
- UI.warn "The query(`#{query}`) not found pod." unless opened
end
end
+
+ def update_specs_repos
+ unless config.skip_repo_update?
+ UI.section 'Updating spec repositories' do
+ SourcesManager.update
+ end
+ end
+ end
+
+ def spec_with_name(name)
+ if set = SourcesManager.search(Dependency.new(name))
+ set.specification.root
+ else
+ raise Informative, "Unable to find a podspec named `#{name}`"
+ end
+ end
+
+ def pick_open_url(spec)
+ url = spec.homepage
+ if @spec && url =~ %r|^https?://github.com/|
+ "%s/tree/master/%s.podspec" % [ url, spec.name ]
+ else
+ url
+ end
+ end
+
end
end
end