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

Already on GitHub? Sign in to your account

Command to print info on used libraries in project #855

Closed
xslim opened this Issue Mar 13, 2013 · 13 comments

Comments

Projects
None yet
2 participants
Contributor

xslim commented Mar 13, 2013

Recently I come up of needing to get info on Pods that are used by the project. I needed that for making documentation.

So I come up with a fast script that prints pod info in markdown

#!/usr/bin/env ruby

require 'cocoapods'

podfile = Pod::Podfile.from_file('Podfile')
pods = []
podfile.root_target_definitions.each {|e| h = e.to_hash; pods << h['dependencies'] if h['dependencies']}
pods.flatten!
pods.collect! {|pod| (pod.is_a?(Hash)) ? pod.keys.first : pod}

s = []
pods.each do |pod|
  spec = Pod::SourcesManager.search_by_name(pod).first
  name = spec.specification.name
  url = spec.specification.homepage
  summary = spec.specification.summary

  s << "  * [#{name}](#{url}) - #{summary}"
end

puts s * "\n"

which outputs:


  • Injective - Cocoa / Cocoa Touch Dependency Injection framework with features for simpler TDD.
  • AFNetworking - A delightful iOS and OS X networking framework.
  • RestKit - RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X.
  • SVProgressHUD - A clean and lightweight progress HUD for your iOS app.
  • AdMob - An unofficial clone of the Google AdMob SDK for iOS.
  • TestFlightSDK - TestFlightSDK for over-the-air beta testing and crash reporting.
  • DCIntrospect - Introspect is small set of tools for iOS that aid in debugging user interfaces built with UIKit.
  • Calabash - Calabash is an automated testing technology for Android and iOS native and hybrid applications.

What I would like is to have some command like pod podfile info --md that will do the same to use it in automated documentation generation

Owner

fabiopelosin commented Apr 10, 2013

This depends in #959, although it can be implemented in CocoaPods in the meanwhile and when the plug-in system is ready extracted to a dedicated gem.

Contributor

xslim commented Apr 10, 2013

Where is the best to implement it? CocoaPods/CocoaPods or CocoaPods/Core ?

Owner

fabiopelosin commented Apr 10, 2013

This command or the plugin system?

Contributor

xslim commented Apr 10, 2013

I would like to put a few methods and after, command that will print out the info

def podfile_info_hash(podfile, keys=[:name, :homepage, :summary])
    pods = []
    podfile.root_target_definitions.each {|e| h = e.to_hash; pods << h['dependencies'] if h['dependencies']}
    pods.flatten!
    pods.collect! {|pod| (pod.is_a?(Hash)) ? pod.keys.first : pod}

    pods_info = []
    pods.each do |pod|
      spec = Pod::SourcesManager.search_by_name(pod).first
      info = {}
      keys.each { |k| info[k] = spec.specification.send(k) }
      pods_info << info
    end
    pods_info
  end

  def podfile_info(podfile)
    pods = podfile_info_hash(podfile, [:name, :homepage, :summary])
    pods.each { |pod| puts "* [#{pod[:name]}](#{pod[:homepage]}) - #{pod[:summary]}" }
  end

# test
podfile = Pod::Podfile.from_file(file)
podfile_info(podfile)
Contributor

xslim commented Apr 10, 2013

Do you personally have a use case / ideas for such command? What would be the preferred output?

Owner

fabiopelosin commented Apr 10, 2013

The command would be best implemented in CocoaPods/CocoaPods until the plug-in system is set in place.

I like the idea, I would use it to inspect the Pods of a project, for example one that I'm checking out from GitHub. It would be nice also to have a command line output without the urls. Finally I think that it might be better to ask the Lockfile for the Pods (see #pod_names).

To get started you could check the outdated command.

Contributor

xslim commented Apr 10, 2013

OK, let's think
Command line pod podfile info - will print out to console

Pods used:
- PodName - Pod summary

Optional options:

  • --md - will output just the Markdown to console (with url, to pass to your documentation, etc)
  • --all - will output all Pods with dependencies that are used in a project

Something like this?

Owner

fabiopelosin commented Apr 10, 2013

Sounds good. I would name the command something like installation-info, i.e. I would not create the abstract parent command podfile.

Contributor

xslim commented Apr 10, 2013

Well, the output is related to Podfile… and installation-info can be something different….
Maybe after a while, podfile command will be extended with something different… ?

Owner

fabiopelosin commented Apr 10, 2013

Well, the output is related to Podfile

My previous comment reflects my opinion expressed before that it should check the Lockfile (i.e. the installation). The proposal was not the best and could be improved thought 😄

Maybe after a while, podfile command will be extended with something different… ?

I don't that we should create an abstract command just in case it might be used (YAGNI). If you still are of the idea that it should report the contents of the Podfile instead of the ones of the Lockfile, I think that for now a good command would be podfile-info.

Contributor

xslim commented Apr 10, 2013

I think using a lock file if fine with --all. So how should I name the Class and a command?

Owner

fabiopelosin commented Apr 10, 2013

The lockfile will return all the Pods (#pod_names, or the ones of the Podfile with #dependencies). This is better because if you would use the Podfile you would need to kick the resolver for the --all option.

For the name... you pick! 👺

Owner

fabiopelosin commented Apr 10, 2013

Mhmm my japanese goblin looks worse than expected... it was supposed to be a more trollish figure 😄

@fabiopelosin fabiopelosin added a commit that referenced this issue Apr 15, 2013

@fabiopelosin fabiopelosin Merge pull request #962 from xslim/master
New command podfile-info - Shows information on installed Pods #855
f6c041e

@jzapater jzapater pushed a commit to jzapater/CocoaPods that referenced this issue Sep 17, 2013

@keith keith Merge pull request #855 from dkuhnke/master
CoreTextLabel 1.2.4
321fd45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment