Skip to content

Commit

Permalink
Add simple command executer.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Sep 17, 2011
1 parent 71fc2bb commit eed0a91
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
1 change: 1 addition & 0 deletions TODO
@@ -0,0 +1 @@
* Check exit statuses of commands performed and raise when necessary.
2 changes: 1 addition & 1 deletion examples/Podfile
Expand Up @@ -2,7 +2,7 @@
dependency 'SSZipArchive', '>= 1' dependency 'SSZipArchive', '>= 1'


#dependency 'ASIHTTPRequest', '1.8' #dependency 'ASIHTTPRequest', '1.8'
#dependency 'ASIWebPageRequest', '= 1.8' dependency 'ASIWebPageRequest', '= 1.8'


# is part of ASIHTTPRequest 1.8 and 1.8.1 # is part of ASIHTTPRequest 1.8 and 1.8.1
dependency 'Reachability' #, '>= 2.0' dependency 'Reachability' #, '>= 2.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoa_pods.rb
Expand Up @@ -6,6 +6,7 @@ class Informative < StandardError
autoload :Config, 'cocoa_pods/config' autoload :Config, 'cocoa_pods/config'
autoload :Dependency, 'cocoa_pods/dependency' autoload :Dependency, 'cocoa_pods/dependency'
autoload :Downloader, 'cocoa_pods/downloader' autoload :Downloader, 'cocoa_pods/downloader'
autoload :Executable, 'cocoa_pods/executable'
autoload :Installer, 'cocoa_pods/installer' autoload :Installer, 'cocoa_pods/installer'
autoload :Resolver, 'cocoa_pods/resolver' autoload :Resolver, 'cocoa_pods/resolver'
autoload :Source, 'cocoa_pods/source' autoload :Source, 'cocoa_pods/source'
Expand All @@ -19,7 +20,6 @@ module Xcode
end end


autoload :Pathname, 'pathname' autoload :Pathname, 'pathname'
autoload :Executioner, 'executioner'
end end


class Pathname class Pathname
Expand Down
2 changes: 2 additions & 0 deletions lib/cocoa_pods/command.rb
Expand Up @@ -40,6 +40,7 @@ def self.banner


def self.options def self.options
" --help Show help information\n" + " --help Show help information\n" +
" --silent Print nothing\n" +
" --verbose Print more information while working" " --verbose Print more information while working"
end end


Expand All @@ -59,6 +60,7 @@ def self.run(*argv)
def self.parse(*argv) def self.parse(*argv)
argv = ARGV.new(argv) argv = ARGV.new(argv)
show_help = argv.option('--help') show_help = argv.option('--help')
Config.instance.silent = argv.option('--silent')
Config.instance.verbose = argv.option('--verbose') Config.instance.verbose = argv.option('--verbose')


command_class = case argv.shift_argument command_class = case argv.shift_argument
Expand Down
3 changes: 1 addition & 2 deletions lib/cocoa_pods/command/repo.rb
@@ -1,4 +1,3 @@
require 'executioner'
require 'fileutils' require 'fileutils'


module Pod module Pod
Expand All @@ -23,7 +22,7 @@ def self.banner
Changes the current working dir to the local spec-repo `NAME'.} Changes the current working dir to the local spec-repo `NAME'.}
end end


include Executioner extend Executable
executable :git executable :git


def initialize(argv) def initialize(argv)
Expand Down
12 changes: 4 additions & 8 deletions lib/cocoa_pods/downloader.rb
Expand Up @@ -16,11 +16,7 @@ def initialize(pod_root, url, options)
end end


class Git < Downloader class Git < Downloader
require 'executioner' extend Executable
include Executioner
# TODO make Executioner:
# * not raise when there's output to either stdout/stderr, but check exit status
# * sync output
executable :git executable :git


def download def download
Expand All @@ -38,16 +34,16 @@ def download_tag
Dir.chdir(@pod_root) do Dir.chdir(@pod_root) do
git "init" git "init"
git "remote add origin '#{@url}'" git "remote add origin '#{@url}'"
git "fetch origin tags/#{@options[:tag]} 2>&1" git "fetch origin tags/#{@options[:tag]}"
git "reset --hard FETCH_HEAD" git "reset --hard FETCH_HEAD"
git "checkout -b activated-pod-commit 2>&1" git "checkout -b activated-pod-commit"
end end
end end


def download_commit def download_commit
git "clone '#{@url}' '#{@pod_root}'" git "clone '#{@url}' '#{@pod_root}'"
Dir.chdir(@pod_root) do Dir.chdir(@pod_root) do
git "checkout -b activated-pod-commit #{@options[:commit]} 2>&1" git "checkout -b activated-pod-commit #{@options[:commit]}"
end end
end end


Expand Down
13 changes: 13 additions & 0 deletions lib/cocoa_pods/executable.rb
@@ -0,0 +1,13 @@
module Pod
module Executable
def executable(name)
define_method(name) do |command|
if Config.instance.verbose?
`#{name} #{command} 1>&2`
else
`#{name} #{command} 2> /dev/null`
end
end
end
end
end
3 changes: 1 addition & 2 deletions spec/spec_helper/git.rb
@@ -1,5 +1,4 @@
require 'spec_helper/temporary_directory' require 'spec_helper/temporary_directory'
require 'executioner'


module SpecHelper module SpecHelper
def self.tmp_repos_path def self.tmp_repos_path
Expand All @@ -16,7 +15,7 @@ def tmp_master_repo_path
tmp_repos_path + 'master' tmp_repos_path + 'master'
end end


include Executioner extend Pod::Executable
executable :git executable :git


alias_method :git_super, :git alias_method :git_super, :git
Expand Down

0 comments on commit eed0a91

Please sign in to comment.