Commit b3f6eb2a authored by Raphael Sobik's avatar Raphael Sobik

Adds pod spec cat subcommand

The command searches for the specfile and prints the most
recent version onto standard out.
parent 482c9589
......@@ -13,6 +13,8 @@
- Added Podfile to the Pods project.
[#476](https://github.com/CocoaPods/CocoaPods/issues/476)
- Adds new subcommand `pod spec cat NAME` to print a spec file to standard output.
## Master
[CocoaPods](https://github.com/CocoaPods/CocoaPods/compare/0.16.0.rc2...master)[Xcodeproj](https://github.com/CocoaPods/Xcodeproj/compare/0.4.0.rc1...master)
......
......@@ -126,6 +126,56 @@ module Pod
end
end
class Cat < Spec
self.summary = 'Prints a spec file'
self.description = <<-DESC
Prints `NAME.podspec` to standard output.
DESC
self.arguments = '[ NAME.podspec ]'
def initialize(argv)
@name = argv.shift_argument
super
end
def validate!
super
help! "A pod name is required." unless @name
end
def run
found_sets = Source.search_by_name(@name)
raise Informative, "Unable to find a spec named `#{@name}'." if found_sets.count == 0
unless found_sets.count == 1
names = found_sets.map(&:name) * ', '
raise Informative, "More that one fitting spec found:\n #{names}"
end
set = found_sets.first
best_spec = best_spec_from_set(set)
file_name = best_spec.defined_in_file
UI.puts File.open(file_name).read
end
def best_spec_from_set(set)
sources = set.sources
best_source = sources.first
best_version = best_source.versions(set.name).first
sources.each do |source|
if source.versions(set.name).first > best_version
best_source = source
best_version = version
end
end
best_spec = best_source.specification(set.name, best_version)
end
end
# TODO some of the following methods can probably move to one of the subclasses.
private
......
......@@ -136,4 +136,28 @@ module Pod
UI.output.should.include "Missing license type"
end
end
describe "Command::Spec#cat" do
extend SpecHelper::TemporaryDirectory
extend SpecHelper::TemporaryRepos
it "complains it cant't find a spec to read" do
lambda { command('spec', 'cat', 'not-exissting-spec').run }.should.raise Informative
end
it "complains provided spec name is ambigious" do
e = lambda { command('spec', 'cat', 'AF').run }.should.raise Informative
e.message.should.match /More that one/
end
it "prints the spec on standard output" do
lambda { command('spec', 'cat', 'JRSwizzle').run }.should.not.raise
text = (fixture('spec-repos') + 'master/JRSwizzle/1.0/JRSwizzle.podspec').read
#output.gsub(/\n/,'').should.equsal text.gsub(/\n/,'')
UI.output.should.include text.gsub(/\n/,'')
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment