Skip to content

Commit

Permalink
Move from podspec_location to podspec_name
Browse files Browse the repository at this point in the history
The flag is poorly named, this is more clear and the other
functionality is not supported of using a subdirectory. Only
a .podspec file of a different name than the git repo is
supported, and this corrects the functionality based on that.

The podspec file still has to be located in the root of the git repo.
  • Loading branch information
rockwotj committed Jun 12, 2016
1 parent 590fb5a commit 3cfd14f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
22 changes: 11 additions & 11 deletions lib/pod/command/try.rb
Expand Up @@ -17,28 +17,28 @@ class Try < Command
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.
If a Git URL is specified, then a --podspec_name can be provided,
if the podspec name is different than the git repo for some reason.
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'],
['--podspec_name=[name]', 'The name of the podspec file within the Git Repository'],
].concat(super)
end

def initialize(argv)
@name = argv.shift_argument
@podspec_location = argv.option('podspec_location')
@podspec_name = argv.option('podspec_name')
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)
help! 'Podspec name can only be used with a Git URL' if @podspec_name && !git_url?(@name)
end

def run
Expand Down Expand Up @@ -73,7 +73,7 @@ def run
#
def setup_spec_in_sandbox(sandbox)
if git_url?(@name)
spec = spec_with_url(@name, @podspec_location)
spec = spec_with_url(@name, @podspec_name)
sandbox.store_pre_downloaded_pod(spec.name)
else
update_specs_repos
Expand Down Expand Up @@ -105,23 +105,23 @@ def spec_with_name(name)
# @param [String] url
# The URL for the pod Git repository.
#
# @param [String] spec_location
# The path to the podspec within the Git repository.
# @param [String] spec_name
# The name of the podspec file within the Git repository.
#
# @return [Specification] The specification.
#
def spec_with_url(url, spec_location = nil)
def spec_with_url(url, spec_name = nil)
name = url.split('/').last
name = name.chomp('.git') if name.end_with?('.git')
name = spec_name unless spec_name.nil?

target_dir = TRY_TMP_DIR + name
target_dir.rmtree if target_dir.exist?

downloader = Pod::Downloader.for_target(target_dir, :git => url)
downloader.download

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

Expand Down
10 changes: 5 additions & 5 deletions spec/command/try_spec.rb
Expand Up @@ -19,11 +19,11 @@ 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))
it 'presents the help if name and podspec name is provided' do
command = Pod::Command.parse(%w(try ARAnalytics --podspec_name=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.message.should.match(/Podspec name can only be used with a Git URL/)
end

before do
Expand Down Expand Up @@ -107,14 +107,14 @@ module Pod
spec.should == stub_spec
end

it 'returns a spec for an https git repo with podspec_location option' do
it 'returns a spec for an https git repo with podspec_name 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 = @sut.spec_with_url('https://github.com/orta/ARAnalytics.git', 'Analytics')
spec.should == stub_spec
end
end
Expand Down

0 comments on commit 3cfd14f

Please sign in to comment.