Skip to content

Commit

Permalink
Merge pull request #55 from rockwotj/master
Browse files Browse the repository at this point in the history
Added a command line option for specifying the podspec file from Git URL
  • Loading branch information
orta committed May 27, 2016
2 parents 170238b + 322ab93 commit 590fb5a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/pod/command/try.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,29 @@ class Try < Command
Downloads the Pod with the given `NAME` (or Git `URL`), install its
dependencies if needed and opens its demo project. If a Git URL is
provided the head of the repo is used.
If a Git URL is specified, then a --podspec_location can be provided,
which is the path to the podspec within the Git Repository.
DESC

self.arguments = [CLAide::Argument.new(%w(NAME URL), true)]

def self.options
[
['--podspec_location=[path]', 'The location to the podspec file within the Git Repository'],
].concat(super)
end

def initialize(argv)
@name = argv.shift_argument
@podspec_location = argv.option('podspec_location')
super
end

def validate!
super
help! 'A Pod name or URL is required.' unless @name
help! 'Location to podspec can only be used with a Git URL' if @podspec_location && !git_url?(@name)
end

def run
Expand Down Expand Up @@ -62,7 +73,7 @@ def run
#
def setup_spec_in_sandbox(sandbox)
if git_url?(@name)
spec = spec_with_url(@name)
spec = spec_with_url(@name, @podspec_location)
sandbox.store_pre_downloaded_pod(spec.name)
else
update_specs_repos
Expand Down Expand Up @@ -91,12 +102,15 @@ def spec_with_name(name)
# Returns the specification found in the given Git repository URL by
# downloading the repository.
#
# @param [String] url
# The URL for the pod Git repository.
# @param [String] url
# The URL for the pod Git repository.
#
# @param [String] spec_location
# The path to the podspec within the Git repository.
#
# @return [Specification] The specification.
#
def spec_with_url(url)
def spec_with_url(url, spec_location = nil)
name = url.split('/').last
name = name.chomp('.git') if name.end_with?('.git')

Expand All @@ -106,7 +120,8 @@ def spec_with_url(url)
downloader = Pod::Downloader.for_target(target_dir, :git => url)
downloader.download

spec_file = Pathname.glob(target_dir + "#{name}.podspec{,.json}").first
spec_location = "#{name}.podspec{,.json}" if spec_location.nil?
spec_file = Pathname.glob(target_dir + spec_location).first
Pod::Specification.from_file(spec_file)
end

Expand Down
18 changes: 18 additions & 0 deletions spec/command/try_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ module Pod
end.message.should.match(/A Pod name or URL is required/)
end

it 'presents the help if name and location is provided' do
command = Pod::Command.parse(%w(try ARAnalytics --podspec_location=Analytics.podspec))
should.raise CLAide::Help do
command.validate!
end.message.should.match(/Location to podspec can only be used with a Git URL/)
end

before do
@original_install_method = method = Pod::Command::Try.instance_method(:install_pod)
Pod::Command::Try.send(:define_method, :install_pod) do |*args|
Expand Down Expand Up @@ -99,6 +106,17 @@ module Pod
spec = @sut.spec_with_url('https://github.com/orta/ARAnalytics.git')
spec.should == stub_spec
end

it 'returns a spec for an https git repo with podspec_location option' do
require 'cocoapods-downloader/git'
Pod::Downloader::Git.any_instance.expects(:download)
spec_file = Pod::Command::Try::TRY_TMP_DIR + 'ARAnalytics/Analytics.podspec'
Pathname.stubs(:glob).once.returns([spec_file])
stub_spec = stub
Pod::Specification.stubs(:from_file).with(spec_file).returns(stub_spec)
spec = @sut.spec_with_url('https://github.com/orta/ARAnalytics.git', 'Analytics.podspec')
spec.should == stub_spec
end
end

it 'installs the pod' do
Expand Down

0 comments on commit 590fb5a

Please sign in to comment.