Commit fa5d18a2 authored by Eloy Duran's avatar Eloy Duran

Dynamically justify options in help output.

parent fba48103
......@@ -23,9 +23,18 @@ module Pod
'Options',
'-------',
'',
@command_class.options
options
].join("\n")
end
private
def options
options = @command_class.options
keys = options.map(&:first)
key_size = keys.inject(0) { |size, key| key.size > size ? key.size : size }
options.map { |key, desc| " #{key.ljust(key_size)} #{desc}" }.join("\n")
end
end
class ARGV < Array
......@@ -47,10 +56,12 @@ module Pod
end
def self.options
" --help Show help information\n" \
" --silent Print nothing\n" \
" --verbose Print more information while working\n" \
" --version Prints the version of CocoaPods"
[
['--help', 'Show help information'],
['--silent', 'Print nothing'],
['--verbose', 'Print more information while working'],
['--version', 'Prints the version of CocoaPods'],
]
end
def self.run(*argv)
......
......@@ -24,12 +24,13 @@ module Pod
end
def self.options
" --no-clean Leave SCM dirs like `.git' and `.svn' in tact after downloading\n" +
" --no-doc Skip documentation generation with appledoc\n" +
" --force-doc Force the generation of documentation\n" +
" --no-integrate Skip integration of the Pods libraries in the Xcode project(s)\n" +
" --no-update Skip running `pod repo update` before install\n" +
super
[
["--no-clean", "Leave SCM dirs like `.git' and `.svn' in tact after downloading"],
["--no-doc", "Skip documentation generation with appledoc"],
["--force-doc", "Force the generation of documentation"],
["--no-integrate", "Skip integration of the Pods libraries in the Xcode project(s)"],
["--no-update", "Skip running `pod repo update` before install"],
].concat(super)
end
def initialize(argv)
......
......@@ -14,8 +14,7 @@ module Pod
end
def self.options
" --update runs `pod repo update` before list\n" +
Presenter.options + super
[["--update", "Run `pod repo update` before listing"]].concat(Presenter.options).concat(super)
end
extend Executable
......
......@@ -12,8 +12,7 @@ module Pod
end
def self.options
" --full Search by name, summary, and description\n" +
Presenter.options + super
[["--full", "Search by name, summary, and description"]].concat(Presenter.options).concat(super)
end
def initialize(argv)
......
require 'net/http'
module Pod
class Command
module SetPresent
def self.options
[
["--name-only", "Show only the names of the pods"],
["--stats", "Show additional stats (like GitHub watchers and forks)"],
]
end
def list
@list
end
def parse_set_options(argv)
@stats = argv.option('--stats')
@list = argv.option('--name-only')
end
def present_sets(array)
array.each do |set|
present_set(set)
end
end
def present_set(set)
if @list
puts set.name
else
puts "--> #{set.name} (#{set.versions.reverse.join(", ")})".green
puts_wrapped_text(set.specification.summary)
spec = set.specification.part_of_other_pod? ? set.specification.part_of_specification : set.specification
source = spec.source.reject {|k,_| k == :commit || k == :tag }.values.first
puts_detail('Homepage', spec.homepage)
puts_detail('Source', source)
if @stats
stats = stats(source)
puts_detail('Watchers', stats[:watchers])
puts_detail('Forks', stats[:forks])
end
puts
end
end
# adapted from http://blog.macromates.com/2006/wrapping-text-with-regular-expressions/
def puts_wrapped_text(txt, col = 80, indentation = 4)
indent = ' ' * indentation
puts txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n")
end
def puts_detail(title,string)
return if !string
# 8 is the length of homepage
number_of_spaces = ((8 - title.length) > 0) ? (8 - title.length) : 0
spaces = ' ' * number_of_spaces
puts " - #{title}: #{spaces + string}"
end
def stats(url)
original_url, username, reponame = *(url.match(/[:\/]([\w\-]+)\/([\w\-]+)\.git/).to_a)
result = {}
if original_url
gh_response = Net::HTTP.get('github.com', "/api/v2/json/repos/show/#{username}/#{reponame}")
result[:watchers] = gh_response.match(/\"watchers\"\W*:\W*([0-9]+)/).to_a[1]
result[:forks] = gh_response.match(/\"forks\"\W*:\W*([0-9]+)/).to_a[1]
end
result
end
end
end
end
......@@ -15,8 +15,7 @@ module Pod
end
def self.options
" --push Use this option to enable push access once granted\n" +
super
[["--push", "Use this option to enable push access once granted"]].concat(super)
end
extend Executable
......
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