Skip to content

Commit

Permalink
Merge branch master into acknowledgements
Browse files Browse the repository at this point in the history
  • Loading branch information
goonzoid committed May 6, 2012
2 parents 5c62253 + 42cc83a commit edff6c0
Show file tree
Hide file tree
Showing 38 changed files with 1,150 additions and 306 deletions.
1 change: 0 additions & 1 deletion Gemfile
@@ -1,6 +1,5 @@
source "http://rubygems.org"

gem "open4"
gem "colored"
gem "escape"
gem "json"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -38,7 +38,6 @@ GEM
faraday_middleware (~> 0.8)
hashie (~> 1.2)
multi_json (~> 1.0)
open4 (1.3.0)
pry (0.9.8.4)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
Expand All @@ -64,7 +63,6 @@ DEPENDENCIES
kicker
mocha-on-bacon
octokit
open4
pry
rake
rb-fsevent
Expand Down
1 change: 0 additions & 1 deletion cocoapods.gemspec
Expand Up @@ -29,7 +29,6 @@ Gem::Specification.new do |s|
"you are upgrading, first run: $ pod setup"

s.add_runtime_dependency 'xcodeproj', '~> 0.1.0'
s.add_runtime_dependency 'popen4', '~> 0.1.2'
s.add_runtime_dependency 'colored', '~> 1.2'
s.add_runtime_dependency 'escape', '~> 0.0.4'
s.add_development_dependency 'bacon', '~> 1.1'
Expand Down
5 changes: 5 additions & 0 deletions lib/cocoapods.rb
Expand Up @@ -33,6 +33,7 @@ module Generator
autoload :Acknowledgements, 'cocoapods/generator/acknowledgements'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
autoload :Markdown, 'cocoapods/generator/acknowledgements/markdown'
autoload :DummySource, 'cocoapods/generator/dummy_source'
end
end

Expand All @@ -42,3 +43,7 @@ def glob(pattern = '')
end
end

if ENV['COCOA_PODS_ENV'] == 'development'
require 'pry'
require 'awesome_print'
end
34 changes: 18 additions & 16 deletions lib/cocoapods/command.rb
Expand Up @@ -6,6 +6,7 @@ class Command
autoload :Install, 'cocoapods/command/install'
autoload :List, 'cocoapods/command/list'
autoload :Presenter, 'cocoapods/command/presenter'
autoload :Push, 'cocoapods/command/push'
autoload :Repo, 'cocoapods/command/repo'
autoload :Search, 'cocoapods/command/search'
autoload :Setup, 'cocoapods/command/setup'
Expand All @@ -18,12 +19,13 @@ def initialize(command_class, argv)

def message
[
@command_class.banner,
'',
'Options',
'-------',
@command_class.banner.gsub(/\$ pod (.*)/, '$ pod \1'.green),
'',
options
'Options:',
'',
options,
"\n",
].join("\n")
end

Expand All @@ -45,22 +47,19 @@ def shift_argument; (arg = arguments[0]) && delete(arg); end
end

def self.banner
"To see help for the available commands run:\n" \
"\n" \
" * $ pod setup --help\n" \
" * $ pod search --help\n" \
" * $ pod list --help\n" \
" * $ pod install --help\n" \
" * $ pod repo --help\n" \
" * $ pod spec --help"
commands = ['install', 'list', 'push', 'repo', 'search', 'setup', 'spec'].sort
banner = "\nTo see help for the available commands run:\n\n"
commands.each {|cmd| banner << " * $ pod #{cmd.green} --help\n"}
banner
end

def self.options
[
['--help', 'Show help information'],
['--silent', 'Print nothing'],
['--verbose', 'Print more information while working'],
['--version', 'Prints the version of CocoaPods'],
['--help', 'Show help information'],
['--silent', 'Print nothing'],
['--no-color', 'Print output without color'],
['--verbose', 'Print more information while working'],
['--version', 'Prints the version of CocoaPods'],
]
end

Expand Down Expand Up @@ -90,13 +89,16 @@ def self.parse(*argv)
Config.instance.silent = argv.option('--silent')
Config.instance.verbose = argv.option('--verbose')

String.send(:define_method, :colorize) { |string , _| string } if argv.option( '--no-color' )

command_class = case argv.shift_argument
when 'install' then Install
when 'repo' then Repo
when 'search' then Search
when 'list' then List
when 'setup' then Setup
when 'spec' then Spec
when 'push' then Push
end

if show_help || command_class.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods/command/install.rb
Expand Up @@ -35,7 +35,7 @@ def self.options

def initialize(argv)
config.clean = !argv.option('--no-clean')
config.doc = !argv.option('--no-doc')
config.generate_docs = !argv.option('--no-doc')
config.force_doc = argv.option('--force-doc')
config.integrate_targets = !argv.option('--no-integrate')
@update_repo = !argv.option('--no-update')
Expand Down
16 changes: 7 additions & 9 deletions lib/cocoapods/command/presenter.rb
Expand Up @@ -2,7 +2,7 @@ module Pod
class Command
class Presenter
def self.options
" --stats Show additional stats (like GitHub watchers and forks)\n"
[["--stats", "Show additional stats (like GitHub watchers and forks)"]]
end

autoload :CocoaPod, 'cocoapods/command/presenter/cocoa_pod'
Expand All @@ -24,10 +24,11 @@ def describe(set)
result << detail('Homepage', pod.homepage)
result << detail('Source', pod.source_url)
if @stats
result << detail('Pushed', pod.github_last_activity)
result << detail('Authors', pod.authors) if pod.authors =~ /,/
result << detail('Author', pod.authors) if pod.authors !~ /,/
result << detail('Platform', pod.platform)
result << detail('License', pod.license)
result << detail('Platform', pod.platform)
result << detail('Watchers', pod.github_watchers)
result << detail('Forks', pod.github_forks)
end
Expand All @@ -43,18 +44,15 @@ def wrap_string(txt, col = 80, indentation = 4)
txt.strip.gsub(/(.{1,#{col}})( +|$)\n?|(.{#{col}})/, indent + "\\1\\3\n")
end

def detail(title, value, preferred_indentation = 8)
# 8 is the length of Homepage
def detail(title, value)
return '' if !value
number_of_spaces = ((preferred_indentation - title.length) > 0) ? (preferred_indentation - title.length) : 0
spaces = ' ' * number_of_spaces
''.tap do |t|
t << " - #{title}:"
t << " - #{title}:".ljust(16)
if value.class == Array
separator = "\n - "
t << separator + value.join(separator)
t << separator << value.join(separator)
else
t << " #{spaces + value.to_s}\n"
t << value.to_s << "\n"
end
end
end
Expand Down
23 changes: 23 additions & 0 deletions lib/cocoapods/command/presenter/cocoa_pod.rb
Expand Up @@ -72,6 +72,10 @@ def github_forks
Pod::Specification::Statistics.instance.github_forks(@set)
end

def github_last_activity
distance_from_now_in_words(Pod::Specification::Statistics.instance.github_pushed_at(@set))
end

def ==(other)
self.class === other && @set == other.set
end
Expand All @@ -92,6 +96,25 @@ def oxfordify words
"#{words[0..-2].join(', ')}, and #{words.last}"
end
end

def distance_from_now_in_words(from_time)
from_time = Time.parse(from_time)
to_time = Time.now
distance_in_days = (((to_time - from_time).abs)/60/60/24).round

case distance_in_days
when 0..7
"less than a week ago"
when 8..29
"#{distance_in_days} days ago"
when 30..45
"1 month ago"
when 46..365
"#{(distance_in_days.to_f / 30).round} months ago"
else
"more than a year ago"
end
end
end
end
end
Expand Down
101 changes: 101 additions & 0 deletions lib/cocoapods/command/push.rb
@@ -0,0 +1,101 @@
require 'fileutils'

module Pod
class Command
class Push < Command
def self.banner
%{Pushing new specifications to a spec-repo:
$ pod push [REPO]
Validates `*.podspec' in the current working dir, updates
the local copy of the repository named REPO, adds specifications
to REPO, and finally it pushes REPO to its remote.}
end

def self.options
[["--allow-warnings", "Allows to push if warnings are not evitable"]].concat(super)
end

extend Executable
executable :git

def initialize(argv)
@allow_warnings = argv.option('--allow-warnings')
@repo = argv.shift_argument
super unless argv.empty? && @repo
end

def run
validate_podspec_files
check_repo_status
update_repo
add_specs_to_repo
push_repo
puts
end

private

def update_repo
puts "Updating the `#{@repo}' repo\n".yellow unless config.silent
# show the output of git even if not verbose
Dir.chdir(repo_dir) { puts `git pull 2>&1` }
end

def push_repo
puts "\nPushing the `#{@repo}' repo\n".yellow unless config.silent
Dir.chdir(repo_dir) { puts `git push 2>&1` }
end

def repo_dir
dir = config.repos_dir + @repo
raise Informative, "[!] `#{@repo}' repo not found".red unless dir.exist?
dir
end

def check_repo_status
# TODO: add specs for staged and unstaged files (tested manually)
clean = Dir.chdir(repo_dir) { `git status --porcelain 2>&1` } == ''
raise Informative, "[!] `#{@repo}' repo not clean".red unless clean
end

def podspec_files
files = Pathname.glob("*.podspec")
raise Informative, "[!] Couldn't find .podspec file in current directory".red if files.empty?
files
end

def validate_podspec_files
puts "\nValidating specs".yellow unless config.silent
lint_argv = ["lint"]
lint_argv << "--only-errors" if @allow_warnings
lint_argv << "--silent" if config.silent
all_valid = Spec.new(ARGV.new(lint_argv)).run
end

def add_specs_to_repo
puts "\nAdding the specs to the #{@repo} repo\n".yellow unless config.silent
podspec_files.each do |spec_file|
spec = Pod::Specification.from_file(spec_file)
output_path = File.join(repo_dir, spec.name, spec.version.to_s)
if Pathname.new(output_path).exist?
message = "[Fix] #{spec}"
elsif Pathname.new(File.join(repo_dir, spec.name)).exist?
message = "[Update] #{spec}"
else
message = "[Add] #{spec}"
end
puts " - #{message}" unless config.silent

FileUtils.mkdir_p(output_path)
FileUtils.cp(Pathname.new(spec.name+'.podspec'), output_path)
Dir.chdir(repo_dir) do
git("add #{spec.name}")
git("commit -m '#{message}'")
end
end
end
end
end
end

0 comments on commit edff6c0

Please sign in to comment.