Permalink
Browse files

Merge pull request #219 from CocoaPods/pod-push

Pod push, pod spec lint, and minor changes
  • Loading branch information...
2 parents f9e77af + 7f7aa87 commit 11616843519fd288370638ce5850ad7af0b055ce @fabiopelosin fabiopelosin committed Apr 26, 2012
View
@@ -1,6 +1,5 @@
source "http://rubygems.org"
-gem "open4"
gem "colored"
gem "escape"
gem "json"
View
@@ -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)
@@ -64,7 +63,6 @@ DEPENDENCIES
kicker
mocha-on-bacon
octokit
- open4
pry
rake
rb-fsevent
View
@@ -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'
View
@@ -39,3 +39,7 @@ def glob(pattern = '')
end
end
+if ENV['COCOA_PODS_ENV'] == 'development'
+ require 'pry'
+ require 'awesome_print'
+end
View
@@ -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'
@@ -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
@@ -45,14 +47,10 @@ 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
@@ -97,6 +95,7 @@ def self.parse(*argv)
when 'list' then List
when 'setup' then Setup
when 'spec' then Spec
+ when 'push' then Push
end
if show_help || command_class.nil?
@@ -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'
@@ -43,18 +43,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
@@ -0,0 +1,100 @@
+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
+ 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
Oops, something went wrong.

0 comments on commit 1161684

Please sign in to comment.