Permalink
Browse files

Merge pull request #8 from guedes/issue_4

Issues: #4, #5
  • Loading branch information...
guedes committed May 23, 2011
2 parents 79a586b + b41312b commit 02a3f1bf8dc305ed00a1cc786690b84e5157188c
Showing with 190 additions and 29 deletions.
  1. +89 −20 README.md
  2. +5 −1 bin/pgxn_utils
  3. +2 −0 lib/pgxn_utils.rb
  4. +73 −4 lib/pgxn_utils/cli.rb
  5. +1 −1 lib/pgxn_utils/version.rb
  6. +7 −0 pgxn_utils.gemspec
  7. +7 −3 spec/cli_spec.rb
  8. +6 −0 spec/spec_helper.rb
View
109 README.md
@@ -1,10 +1,10 @@
pgxn utils
==========
-What is?
+What is it?
--------
-This is a set of task that aims to help PostgreSQL developers to focus more on the problem that they wants to solve than in the all structure and files and control files need to PGXS to build the extension.
+It aims to be a set of task that aims to help PostgreSQL extension's developers to focus more on the problem that they wants to solve than in the all structure and files and control files need to PGXS to build the extension.
It's a WIP but very functional. Please use it and help me improve it.
@@ -16,24 +16,17 @@ How to install it?
How it works?
-------------
- $ pgxn_utils help skeleton
- Usage:
- pgxn_utils skeleton extension_name
+It is all about tasks. Let's see what tasks we have:
- Options:
- -p, [--target=TARGET] # Define the target directory
- # Default: .
- -m, [--maintainer=MAINTAINER] # Maintainer's name
- -e, [--maintainer-mail=MAINTAINER_MAIL] # Maintainer's mail
- -a, [--abstract=ABSTRACT] # Defines a short description to abstract
- -l, [--license=LICENSE] # The extension license.
- -v, [--version=VERSION] # Initial version
- -d, [--description=DESCRIPTION] # A long text that contains more information about extension
- -b, [--generated-by=GENERATED_BY] # Name of extension's generator
- -t, [--tags=one two three] # Defines extension's tags
- -r, [--release-status=RELEASE_STATUS] # Initial extension's release status
-
-See in action...
+ $ pgxn_utils help
+ Tasks:
+ pgxn_utils bundle [extension_name] # Bundles an extension
+ pgxn_utils change [extension_name] # Change META's attributes in current extension
+ pgxn_utils help [TASK] # Describe available tasks or one specific task
+ pgxn_utils skeleton extension_name # Creates an extension skeleton in current directory
+
+
+# Creating a new extension
$ pgxn_utils skeleton my_cool_extension
create my_cool_extension
@@ -47,7 +40,83 @@ See in action...
create my_cool_extension/test/expected/base.out
create my_cool_extension/test/sql/base.sql
-Thats it! Start coding! ":)
+Thats it! Just start coding! ":)
+
+# Changing something
+
+Well suppose you want to change the default maintainer's name and the license, well just do:
+
+ $ pgxn_utils change my_cool_extension --maintainer "Dickson Guedes" --license bsd
+ exist my_cool_extension
+ identical my_cool_extension/my_cool_extension.control
+ conflict my_cool_extension/META.json
+ Overwrite /home/guedes/extensions/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh] d
+ {
+ "name": "my_cool_extension",
+ "abstract": "A short description",
+ "description": "A long description",
+ "version": "0.0.1",
+ - "maintainer": "The maintainer's name",
+ + "maintainer": "Dickson Guedes",
+ - "license": "postgresql",
+ + "license": "bsd",
+ "provides": {
+ "my_cool_extension": {
+ "abstract": "A short description",
+ "file": "sql/my_cool_extension.sql",
+ "docfile": "doc/my_cool_extension.md",
+ "version": "0.0.1"
+ }
+ },
+ "release_status": "unstable",
+
+ "generated_by": "The maintainer's name",
+
+
+ "meta-spec": {
+ "version": "1.0.0",
+ "url": "http://pgxn.org/meta/spec.txt"
+ }
+ }
+ Retrying...
+ Overwrite /home/guedes/extensions/my_cool_extension/META.json? (enter "h" for help) [Ynaqdh]
+ force my_cool_extension/META.json
+ identical my_cool_extension/Makefile
+ ...
+ ...
+ ...
+
+It will wait you decide what to do.
+
+For all switches that you can use with *change*, type:
+
+ $ pgxn_utils help change
+ Usage:
+ pgxn_utils change [extension_name]
+
+ Options:
+ -m, [--maintainer=MAINTAINER] # Maintainer's name <maintainer@email>
+ -a, [--abstract=ABSTRACT] # Defines a short description to abstract
+ -l, [--license=LICENSE] # The extension license.
+ -v, [--version=VERSION] # Initial version
+ -d, [--description=DESCRIPTION] # A long text that contains more information about extension
+ -b, [--generated-by=GENERATED_BY] # Name of extension's generator
+ -t, [--tags=one two three] # Defines extension's tags
+ -r, [--release-status=RELEASE_STATUS] # Initial extension's release status
+
+
+# Bundle it!
+
+Well, since you finished your work you can bundle it to send to [PGXN](http://pgxn.org).
+
+Just type:
+
+ $ pgxn_utils bundle my_cool_extension
+ Extension generated at: /home/guedes/extensions/my_cool_extension-0.0.1.zip
+
+# Working in progress
+
+I'm working in an option to release the bundled extension, sending it to [PGXN](http://pgxn.org).
Copyright and License
---------------------
View
@@ -2,4 +2,8 @@
$:.unshift File.expand_path('..', __FILE__)
$:.unshift File.expand_path('../../lib', __FILE__)
require 'pgxn_utils'
-PgxnUtils::CLI.start
+
+task = __FILE__.split('-')[1] if File.basename(__FILE__) != 'pgxn_utils'
+command_args = [ task ] + ARGV if task
+
+PgxnUtils::CLI.start( command_args || ARGV )
View
@@ -1,5 +1,7 @@
require 'thor'
require 'json'
+require 'zip/zip'
+require 'zippy'
module PgxnUtils
autoload :CLI, 'pgxn_utils/cli'
View
@@ -23,28 +23,97 @@ class CLI < Thor
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"
- def skeleton(extension_name)
+ def skeleton(extension_name,target=nil)
+ self.target = options[:target] || target || "."
self.set_accessors extension_name
directory "root", extension_name
end
+ desc "change [extension_name]", "Change META's attributes in current extension."
+
+ # META required fields
+ method_option :maintainer, :aliases => "-m", :type => :string, :desc => "Maintainer's name <maintainer@email>"
+ #method_option :maintainer_mail, :aliases => "-e", :type => :string, :desc => "Maintainer's mail"
+ method_option :abstract, :aliases => "-a", :type => :string, :desc => "Defines a short description to abstract"
+ method_option :license, :aliases => "-l", :type => :string, :desc => "The extension license."
+ method_option :version, :aliases => "-v", :type => :string, :desc => "Initial version"
+
+ # META optional fields
+ method_option :description, :aliases => "-d", :type => :string, :desc => "A long text that contains more information about extension"
+ 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"
+
+ def change(extension_name=".")
+ path = File.expand_path(extension_name)
+
+ target = File.expand_path('..', path)
+ extension_name = File.basename(path)
+
+ skeleton(extension_name, target)
+ end
+
+ desc "bundle [extension_name]", "Bundles an extension."
+
+ def bundle(extension_name=".")
+ unless is_extension?(extension_name)
+ say "'#{extension_name}' isn't a valid extension"
+ else
+ path = File.expand_path(extension_name)
+ extension_name = File.basename(path)
+
+ self.target = path
+ archive_name = "#{path}-#{config_options['version']}"
+ ext = "zip"
+ archive = "#{archive_name}.#{ext}"
+
+ if can_zip?(archive)
+ Zippy.create(archive) do |zip|
+ Dir["#{path}/**/**"].each do |file|
+ zip["#{extension_name}-#{config_options['version']}/#{file}"] = File.open(file) unless File.directory?(file)
+ end
+ end
+ say "Extension generated at: #{archive}"
+ end
+ end
+ end
+
no_tasks do
+ def can_zip?(archive)
+ can_zip = false
+
+ if File.exists?(archive)
+ if yes? "#{archive} found! Overwrite? [yN]"
+ can_zip = true
+ else
+ can_zip = false
+ end
+ else
+ can_zip = true
+ end
+ end
+
+ def is_extension?(dir=".")
+ File.directory?(dir) && File.exists?("#{dir}/META.json")
+ end
def config_options
- file = "#{self.target}/#{self.extension_name}/META.json"
+ file = ""
+ file = File.join(file, self.target) if self.target != "."
+ file = File.join(file, self.extension_name) if self.extension_name
+ file = File.join(file, "META.json")
+
if File.exist?(file)
@@config_options ||= JSON.load(File.read(file))
else
{}
end
-
end
def set_accessors(extension_name="your_extension_name")
self.extension_name = extension_name
- self.target = options[:target]
self.maintainer = options[:maintainer] || config_options["maintainer"] || "The maintainer's name"
#self.maintainer_mail = options[:maintainer_mail] || config_options["maintainer_mail"] || "maintainer@email.here"
self.abstract = options[:abstract] || config_options["abstract"] || "A short description"
@@ -1,3 +1,3 @@
module PgxnUtils
- VERSION = "0.0.4"
+ VERSION = "0.1.0"
end
View
@@ -22,17 +22,24 @@ Gem::Specification.new do |s|
# dev
s.add_development_dependency "rspec"
+ s.add_development_dependency "simplecov", ">= 0.4.0"
# prod
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<thor>, ["~> 0.14"])
+ s.add_runtime_dependency(%q<rubyzip>, ["~> 0.9.4"])
+ s.add_runtime_dependency(%q<zippy>, ["~> 0.1.0"])
else
s.add_dependency(%q<thor>, ["~> 0.14"])
+ s.add_runtime_dependency(%q<rubyzip>, ["~> 0.9.4"])
+ s.add_runtime_dependency(%q<zippy>, ["~> 0.1.0"])
end
else
s.add_dependency(%q<thor>, ["~> 0.14"])
+ s.add_runtime_dependency(%q<rubyzip>, ["~> 0.9.4"])
+ s.add_runtime_dependency(%q<zippy>, ["~> 0.1.0"])
end
end
View
@@ -7,7 +7,7 @@
system "rm -rf extension.*"
end
- context "create skeleton" do
+ context "#skeleton" do
before(:each) do
@cli = PgxnUtils::CLI.new
end
@@ -83,12 +83,16 @@
it "should generates a git repo"
end
- context "bundle" do
+ context "#change" do
+ it "should change things"
+ end
+
+ context "#bundle" do
it "should bundle to zip by default"
it "should create the name in semver spec"
end
- context "release" do
+ context "#release" do
it "should send the bundle to PGXN"
end
View
@@ -2,6 +2,8 @@
$:.unshift File.expand_path('../../lib', __FILE__)
require 'rspec'
+require 'simplecov'
+SimpleCov.start
require 'pgxn_utils'
$counter = 0
@@ -21,6 +23,10 @@ def skeleton(extension_name, args=nil)
run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
end
+def change(extension_name, args=nil)
+ run_pgxn_utils(:skeleton, "#{extension_name} #{args}")
+end
+
def run_pgxn_utils(task, args)
system "#{BIN_PATH} #{task.to_s} #{args} >/dev/null"
end

0 comments on commit 02a3f1b

Please sign in to comment.