Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added initial git support. ref #16

  • Loading branch information...
commit fcea520370dd07d84e07660a09e2baf5ed8e4b31 1 parent 9602960
@guedes guedes authored
View
1  lib/pgxn_utils.rb
@@ -5,6 +5,7 @@
require 'net/http/post/multipart'
require 'net/https'
require 'highline/import'
+require 'grit'
module PgxnUtils
autoload :CLI, 'pgxn_utils/cli'
View
5 lib/pgxn_utils/cli.rb
@@ -7,6 +7,7 @@ class CLI < Thor
include Thor::Actions
include PgxnUtils::NoTasks
+ include Grit
desc "skeleton extension_name", "Creates an extension skeleton in current directory"
@@ -23,6 +24,7 @@ class CLI < Thor
method_option :generated_by, :aliases => "-b", :type => :string, :desc => "Name of extension's generator"
method_option :tags, :aliases => "-t", :type => :array, :desc => "Defines extension's tags"
method_option :release_status, :aliases => "-r", :type => :string, :desc => "Initial extension's release status"
+ method_option :git, :type => :boolean, :default => false, :desc => "Initialize a git repository after create the extension"
def skeleton(extension_name,target=nil)
self.target = options[:target] || target || "."
@@ -35,8 +37,9 @@ def skeleton(extension_name,target=nil)
say "Can't create an extension overwriting an existing directory.", :red
else
self.set_accessors extension_name
-
directory "root", extension_name
+
+ Repo.init("#{self.target}/#{extension_name}") if options[:git]
end
end
View
4 pgxn_utils.gemspec
@@ -57,7 +57,9 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "zippy", "~> 0.1.0"
s.add_runtime_dependency "multipart-post", "~> 1.1.2"
s.add_runtime_dependency "highline", "~> 1.6.2"
+ s.add_runtime_dependency "grit", "~> 2.4.1"
s.add_development_dependency "rspec"
+ s.add_development_dependency "mocha"
s.add_development_dependency "simplecov", "~> 0.4.0"
else
s.add_dependency "json", "~> 1.5.2"
@@ -66,6 +68,7 @@ Gem::Specification.new do |s|
s.add_dependency "zippy", "~> 0.1.0"
s.add_dependency "multipart-post", "~> 1.1.2"
s.add_dependency "highline", "~> 1.6.2"
+ s.add_dependency "grit", "~> 2.4.1"
end
else
s.add_dependency "json", "~> 1.5.2"
@@ -74,5 +77,6 @@ Gem::Specification.new do |s|
s.add_dependency "zippy", "~> 0.1.0"
s.add_dependency "multipart-post", "~> 1.1.2"
s.add_dependency "highline", "~> 1.6.2"
+ s.add_dependency "grit", "~> 2.4.1"
end
end
View
24 spec/cli_spec.rb
@@ -14,14 +14,15 @@
context "#skeleton" do
before(:each) do
- @cli = PgxnUtils::CLI.new
+ system "rm -rf /tmp/extension.*"
+ system "rm -rf extension.*"
end
it "should accepts or not a target" do
expected_extension = next_extension
File.should_not exist(expected_extension)
- skeleton "#{expected_extension}", "-p /tmp"
+ skeleton "#{expected_extension}", %w|-p /tmp|
File.should exist("/tmp/#{expected_extension}")
File.should_not exist(expected_extension)
@@ -35,10 +36,9 @@
expected_mail = "guedes@none.here"
expected_abstract = "Short description"
expected_description = "Very Long description for my cool extension"
- expected_tags = "one two tree"
expected_version = "1.0.0"
- skeleton expected_extension, "-p /tmp -m #{expected_name} -e #{expected_mail} -t #{expected_tags} -a '#{expected_abstract}' -d '#{expected_description}' -v #{expected_version}"
+ skeleton expected_extension, %W|-p /tmp -m #{expected_name} -e #{expected_mail} -t one two tree -a #{expected_abstract} -d #{expected_description} -v #{expected_version}|
meta = File.read("/tmp/#{expected_extension}/META.json")
meta.should match(/"name": "#{expected_extension}"/)
@@ -86,7 +86,21 @@
].sort
end
- it "should generates a git repo"
+ it "should generates a git repo with --git" do
+ expected_extension = next_extension
+ skeleton "#{expected_extension}", %w|--git|
+
+ File.should exist("#{expected_extension}/.git")
+ lambda{ Grit::Repo.new(expected_extension) }.should_not raise_error
+ end
+
+ it "should not generates a git repo with --no-git" do
+ expected_extension = next_extension
+ skeleton "#{expected_extension}", %w|--no-git|
+
+ File.should_not exist("#{expected_extension}/.git")
+ lambda{ Grit::Repo.new(expected_extension) }.should raise_error
+ end
end
context "#change" do
View
2  spec/no_tasks_spec.rb
@@ -7,6 +7,8 @@
after(:all) do
rm_r("/tmp/teste")
rm_r("/tmp/teste2")
+
+ PgxnUtils::NoTasks.send(:remove_method, :options)
end
context "#resolve_extension_path_and_name" do
View
25 spec/spec_helper.rb
@@ -14,19 +14,36 @@
DESTINATION_ROOT = File.expand_path('../pgxn_utils', __FILE__)
FileUtils.rm_rf(DESTINATION_ROOT)
+RSpec.configure do |config|
+ # capture method from https://github.com/wycats/thor/blob/master/spec/spec_helper.rb#L36-47
+ def capture(stream)
+ begin
+ stream = stream.to_s
+ eval "$#{stream} = StringIO.new"
+ yield
+ result = eval("$#{stream}").string
+ ensure
+ eval("$#{stream} = #{stream.upcase}")
+ end
+
+ result
+ end
+end
+
+
def next_extension
$counter += 1
"extension.#{$counter}"
end
-def skeleton(extension_name, args=nil)
- run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+def skeleton(extension_name, args=[])
+ capture(:stdout) { PgxnUtils::CLI.start([ "skeleton", extension_name ] + args) }
end
def change(extension_name, args=nil)
- run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+ #run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
end
def run_pgxn_utils(task, args)
- system "#{BIN_PATH} #{task.to_s} #{args} >/dev/null"
+ #system "#{BIN_PATH} #{task.to_s} #{args}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.