diff options
author | Dickson S. Guedes | 2011-05-23 02:58:53 +0000 |
---|---|---|
committer | Dickson S. Guedes | 2011-05-23 02:58:53 +0000 |
commit | 02a3f1bf8dc305ed00a1cc786690b84e5157188c (patch) | |
tree | 555146bef6535c6bcbd4b00fbedfbe78937af70f | |
parent | 79a586b90cc4366c02226277b9b081db6f779a54 (diff) | |
parent | b41312be1b62e2d8e1367683710543190464d977 (diff) |
Merge pull request #8 from guedes/issue_4v0.1.0
Issues: #4, #5
-rw-r--r-- | README.md | 109 | ||||
-rwxr-xr-x | bin/pgxn_utils | 6 | ||||
-rw-r--r-- | lib/pgxn_utils.rb | 2 | ||||
-rw-r--r-- | lib/pgxn_utils/cli.rb | 77 | ||||
-rw-r--r-- | lib/pgxn_utils/version.rb | 2 | ||||
-rw-r--r-- | pgxn_utils.gemspec | 7 | ||||
-rw-r--r-- | spec/cli_spec.rb | 10 | ||||
-rw-r--r-- | spec/spec_helper.rb | 6 |
8 files changed, 190 insertions, 29 deletions
@@ -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 --------------------- diff --git a/bin/pgxn_utils b/bin/pgxn_utils index 671c4bf..758a5ad 100755 --- a/bin/pgxn_utils +++ b/bin/pgxn_utils @@ -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 ) diff --git a/lib/pgxn_utils.rb b/lib/pgxn_utils.rb index c68f812..c3750bb 100644 --- a/lib/pgxn_utils.rb +++ b/lib/pgxn_utils.rb @@ -1,5 +1,7 @@ require 'thor' require 'json' +require 'zip/zip' +require 'zippy' module PgxnUtils autoload :CLI, 'pgxn_utils/cli' diff --git a/lib/pgxn_utils/cli.rb b/lib/pgxn_utils/cli.rb index 2c06a9b..b8a2c9a 100644 --- a/lib/pgxn_utils/cli.rb +++ b/lib/pgxn_utils/cli.rb @@ -23,28 +23,97 @@ module PgxnUtils 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" diff --git a/lib/pgxn_utils/version.rb b/lib/pgxn_utils/version.rb index 8fd09e0..d297d9d 100644 --- a/lib/pgxn_utils/version.rb +++ b/lib/pgxn_utils/version.rb @@ -1,3 +1,3 @@ module PgxnUtils - VERSION = "0.0.4" + VERSION = "0.1.0" end diff --git a/pgxn_utils.gemspec b/pgxn_utils.gemspec index ca90c70..c6d0e25 100644 --- a/pgxn_utils.gemspec +++ b/pgxn_utils.gemspec @@ -22,6 +22,7 @@ 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 @@ -29,10 +30,16 @@ Gem::Specification.new do |s| 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 diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 578e373..aa346ed 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -7,7 +7,7 @@ describe PgxnUtils::CLI do system "rm -rf extension.*" end - context "create skeleton" do + context "#skeleton" do before(:each) do @cli = PgxnUtils::CLI.new end @@ -83,12 +83,16 @@ describe PgxnUtils::CLI do 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f078b0b..894f648 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,8 @@ $:.unshift File.expand_path('..', __FILE__) $:.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 |