Skip to content
Browse files

Implement `repo add`.

  • Loading branch information...
1 parent 7ce508b commit 2e909ac2d199f17d038855f028f7433abcdabe1c @alloy alloy committed Aug 14, 2011
View
5 lib/cocoa_pods/command.rb
@@ -17,10 +17,11 @@ def self.parse(*argv)
end
def initialize(*argv)
- raise "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
+ raise ArgumentError, "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
end
- def run
+ def repos_dir
+ File.expand_path('~/.cocoa-pods')
end
end
end
View
33 lib/cocoa_pods/command/repo.rb
@@ -1,6 +1,39 @@
+require 'executioner'
+require 'fileutils'
+
module Pod
class Command
class Repo < Command
+ include Executioner
+ executable :git
+
+ def initialize(*argv)
+ case @action = argv[0]
+ when'add'
+ unless (@name = argv[1]) && (@url = argv[2])
+ raise ArgumentError, "needs a NAME and URL"
+ end
+ when 'cd'
+ unless @name = argv[1]
+ raise ArgumentError, "needs a NAME"
+ end
+ else
+ super
+ end
+ end
+
+ def dir
+ File.join(repos_dir, @name)
+ end
+
+ def run
+ send @action
+ end
+
+ def add
+ FileUtils.mkdir_p(repos_dir)
+ Dir.chdir(repos_dir) { git("clone #{@url} #{@name}") }
+ end
end
end
end
View
21 lib/cocoa_pods/command/setup.rb
@@ -1,27 +1,18 @@
-require 'fileutils'
-require 'executioner'
+require 'cocoa_pods/command/repo'
module Pod
class Command
class Setup < Command
- include Executioner
- executable :git
-
- def repos_dir
- File.expand_path('~/.cocoa-pods')
- end
-
- def master_repo_dir
- File.join(repos_dir, 'master')
- end
-
def master_repo_url
'git://github.com/alloy/cocoa-pod-specs.git'
end
+ def add_master_repo_command
+ @command ||= Repo.new('add', 'master', master_repo_url)
+ end
+
def run
- FileUtils.mkdir_p(repos_dir)
- Dir.chdir(repos_dir) { git("clone #{master_repo_url} master") }
+ add_master_repo_command.run
end
end
end
View
15 spec/functional/command_spec.rb
@@ -8,14 +8,19 @@
extend SpecHelper::TemporaryDirectory
it "creates the local spec-repos directory and creates a clone of the `master' repo" do
- #log!
+ command = Pod::Command.parse('setup')
+ def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
+ def (command.add_master_repo_command).repos_dir; SpecHelper.tmp_repos_path; end
- command = Pod::Command.parse("setup")
+ command.run
+ git_config('master', 'remote.origin.url').should == fixture('master-spec-repo.git')
+ end
+
+ it "adds a spec-repo" do
+ command = Pod::Command.parse('repo', 'add', 'private', fixture('master-spec-repo.git'))
def command.repos_dir; SpecHelper.tmp_repos_path; end
- def command.master_repo_url; SpecHelper.fixture('master-spec-repo.git'); end
command.run
- File.should.exist command.master_repo_dir
- git_config('remote.origin.url').should == command.master_repo_url
+ git_config('private', 'remote.origin.url').should == fixture('master-spec-repo.git')
end
end
View
8 spec/spec_helper/git.rb
@@ -20,12 +20,12 @@ def tmp_master_repo_path
executable :git
alias_method :git_super, :git
- def git(command)
- Dir.chdir(tmp_master_repo_path) { git_super(command).strip }
+ def git(repo, command)
+ Dir.chdir(File.join(tmp_repos_path, repo)) { git_super(command).strip }
end
- def git_config(attr)
- git "config --get #{attr}"
+ def git_config(repo, attr)
+ git repo, "config --get #{attr}"
end
end
end
View
13 spec/unit/command_spec.rb
@@ -11,7 +11,7 @@
describe "Pod::Command::Setup" do
it "complains about unknown arguments" do
- lambda { Pod::Command::Setup.new('something') }.should.raise
+ lambda { Pod::Command::Setup.new('something') }.should.raise ArgumentError
end
before do
@@ -25,8 +25,15 @@
it "returns the path of the directory where the local spec-repos will be stored" do
@command.repos_dir.should == File.expand_path("~/.cocoa-pods")
end
+end
+
+describe "Pod::Command::Repo" do
+ it "complains about unknown arguments" do
+ lambda { Pod::Command::Repo.new('something') }.should.raise ArgumentError
+ end
- it "returns the path of the directory where the `master' spec-repo will be" do
- @command.master_repo_dir.should == File.expand_path("~/.cocoa-pods/master")
+ it "returns the path of the spec-repo directory" do
+ repo = Pod::Command::Repo.new('cd', 'private')
+ repo.dir.should == File.expand_path("~/.cocoa-pods/private")
end
end

0 comments on commit 2e909ac

Please sign in to comment.
Something went wrong with that request. Please try again.