Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a `spec create NAME` command which creates a stub file.

  • Loading branch information...
commit 9ba5654da25d12a6cd0c92966bbbefc9b2c10faf 1 parent 11a8a32
@alloy alloy authored
View
1  lib/cocoapods/command.rb
@@ -89,3 +89,4 @@ def initialize(argv)
end
end
end
+
View
63 lib/cocoapods/command/spec.rb
@@ -7,22 +7,69 @@ def self.banner
$ pod help spec
pod spec create NAME
- Creates a directory for your new pod, named `NAME', with a default
- directory structure and accompanying `NAME.podspec'.
-
- pod spec init NAME
Creates a PodSpec, in the current working dir, called `NAME.podspec'.
Use this for existing libraries.
- pod spec lint NAME
- Validates `NAME.podspec' from a local spec-repo. In case `NAME' is
- omitted, it defaults to the PodSpec in the current working dir.
+ pod spec lint NAME.podspec
+ Validates `NAME.podspec'. In case `NAME.podspec' is omitted, it defaults
+ to `*.podspec' in the current working dir.
- pod spec push REMOTE
+ pod spec push NAME REMOTE
Validates `NAME.podspec' in the current working dir, copies it to the
local clone of the `REMOTE' spec-repo, and pushes it to the `REMOTE'
spec-repo. In case `REMOTE' is omitted, it defaults to `master'.}
end
+
+ def initialize(argv)
+ super unless argv.arguments.size == 2
+ case argv.arguments.first
+ when 'create', 'lint'
+ @action, @name = argv.arguments.first(2)
+ when 'push'
+ @action, @name, @remote = argv.arguments.first(3)
+ else
+ super
+ end
+ end
+
+ def run
+ send @action
+ end
+
+ def create
+ author = `git config --get user.name`.strip
+ email = `git config --get user.email`.strip
+ spec = <<-SPEC.gsub(/^ /, '')
+ Pod::Spec.new do
+ name '#{@name}'
+ version '1.0.0'
+ summary 'A short description of #{@name}.'
+ homepage 'http://example.com/#{@name}'
+ author '#{author}' => '#{email}'
+ source :git => 'http://example.com/#{@name}.git',
+ :tag => '1.0.0'
+
+ description 'An optional longer description of #{@name}.'
+
+ # A list of file patterns. If the pattern is a directory then the path will
+ # automatically have '*.{h,m,mm,c,cpp' appended.
+ source_files 'Classes', 'Classes/**/*.{h,m}'
+
+ xcconfig 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework'
+ end
+ SPEC
+ (Pathname.pwd + "#{@name}.podspec").open('w') { |f| f << spec }
+ end
+
+ #def lint
+ #file = @name ? Pathname.new(@name) : config.project_podfile
+ #spec = Specification.from_podspec(file)
+ #spec.validate!
+ #end
+
+ #def push
+
+ #end
end
end
end
View
2  lib/cocoapods/specification.rb
@@ -45,7 +45,7 @@ def authors(*names_and_email_addresses)
authors = list.last.is_a?(Hash) ? list.pop : {}
list.each { |name| authors[name] = nil }
end
- @authors = authors || list
+ @authors = authors || list.first
end
alias_method :author, :authors
View
17 spec/functional/command_spec.rb
@@ -38,6 +38,23 @@ def command.master_repo_url; SpecHelper.fixture('spec-repos/master'); end
(repo3.dir + 'README').read.should.include 'Added!'
end
+ it "creates a new podspec stub file" do
+ Dir.chdir(temporary_directory) do
+ command('spec', 'create', 'Bananas')
+ end
+ path = temporary_directory + 'Bananas.podspec'
+ spec = Pod::Specification.from_podspec(path)
+ spec.read(:name).should == 'Bananas'
+ spec.read(:version).should == Pod::Version.new('1.0.0')
+ spec.read(:summary).should == 'A short description of Bananas.'
+ spec.read(:homepage).should == 'http://example.com/Bananas'
+ spec.read(:authors).should == { `git config --get user.name`.strip => `git config --get user.email`.strip }
+ spec.read(:source).should == { :git => 'http://example.com/Bananas.git', :tag => '1.0.0' }
+ spec.read(:description).should == 'An optional longer description of Bananas.'
+ spec.read(:source_files).should == [Pathname.new('Classes'), Pathname.new('Classes/**/*.{h,m}')]
+ spec.read(:xcconfig).should == { 'OTHER_LDFLAGS' => '-framework SomeRequiredFramework' }
+ end
+
before do
config.repos_dir = fixture('spec-repos')
end
Please sign in to comment.
Something went wrong with that request. Please try again.