Skip to content

Commit

Permalink
Re-use options used at create skeleton to future
Browse files Browse the repository at this point in the history
Now, when you create a new extension and sometime
after try to recreate it with 'skeleton', the
arguments has priority, and that args that isn't
explicit passed again, are re-used from META.json.

Refs #1.
  • Loading branch information
guedes committed May 19, 2011
1 parent e67ed03 commit d8f144e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 34 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -24,21 +24,14 @@ How it works?
-p, [--target=TARGET] # Define the target directory
# Default: .
-m, [--maintainer=MAINTAINER] # Maintainer's name
# Default: The maintainer's name
-e, [--maintainer-mail=MAINTAINER_MAIL] # Maintainer's mail
# Default: maintainer@email.here
-a, [--abstract=ABSTRACT] # Defines a short description to abstract
# Default: A short description
-l, [--license=LICENSE] # The extension license.
# Default: postgresql
-v, [--version=VERSION] # Initial version
# Default: 0.0.1
-d, [--description=DESCRIPTION] # A long text that contains more information about extension
# Default: A long description
-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
# Default: unstable

See in action...

Expand Down
1 change: 1 addition & 0 deletions lib/pgxn_utils.rb
@@ -1,4 +1,5 @@
require 'thor'
require 'json'

module PgxnUtils
autoload :CLI, 'pgxn_utils/cli'
Expand Down
55 changes: 33 additions & 22 deletions lib/pgxn_utils/cli.rb
@@ -1,27 +1,27 @@
module PgxnUtils
class CLI < Thor
attr_accessor :extension_name, :target, :maintainer, :maintainer_mail
attr_accessor :extension_name, :target, :maintainer #, :maintainer_mail
attr_accessor :abstract, :description, :version, :tags
attr_accessor :license, :release_status, :generated_by

include Thor::Actions

desc "skeleton extension_name", "Creates an extension skeleton in current directory."

method_option :target, :aliases => "-p", :default => ".", :desc => "Define the target directory"
method_option :target, :aliases => "-p", :default => ".", :desc => "Define the target directory"

# META required fields
method_option :maintainer, :aliases => "-m", :type => :string, :default => "The maintainer's name", :desc => "Maintainer's name"
method_option :maintainer_mail, :aliases => "-e", :type => :string, :default => "maintainer@email.here", :desc => "Maintainer's mail"
method_option :abstract, :aliases => "-a", :type => :string, :default => "A short description", :desc => "Defines a short description to abstract"
method_option :license, :aliases => "-l", :type => :string, :default => "postgresql", :desc => "The extension license."
method_option :version, :aliases => "-v", :type => :string, :default => "0.0.1", :desc => "Initial version"
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"

This comment has been minimized.

Copy link
@guedes

guedes May 19, 2011

Author Owner

I want to split it in some way to 'maintainer' and 'maintainer mail', but it is really importante?

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, :default => "A long description", :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, :default => "unstable", :desc => "Initial extension's release status"
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 skeleton(extension_name)
self.set_accessors extension_name
Expand All @@ -30,20 +30,31 @@ def skeleton(extension_name)
end

no_tasks do

def config_options
file = "#{self.target}/#{self.extension_name}/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]
self.maintainer_mail = options[:maintainer_mail]
self.abstract = options[:abstract]
self.license = options[:license]
self.version = options[:version]

self.description = options[:description]
self.generated_by = options[:generated_by]
self.tags = options[:tags]
self.release_status = options[:release_status]
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"
self.license = options[:license] || config_options["license"] || "postgresql"
self.version = options[:version] || config_options["version"] || "0.0.1"

self.description = options[:description] || config_options["description"] || "A long description"
self.generated_by = options[:generated_by] || config_options["generated_by"] || maintainer
self.tags = options[:tags] || config_options["tags"]
self.release_status = options[:release_status] || config_options["release_status"] || "unstable"

self.destination_root = target
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pgxn_utils/templates/root/META.json.tt
Expand Up @@ -3,7 +3,7 @@
"abstract": "<%= abstract %>",
"description": "<%= description %>",
"version": "<%= version %>",
"maintainer": "<%= maintainer %> <<%= maintainer_mail %>>",
"maintainer": "<%= maintainer %>",
"license": "<%= license %>",
"provides": {
"<%= extension_name %>": {
Expand Down
2 changes: 1 addition & 1 deletion lib/pgxn_utils/templates/root/sql/%extension_name%.sql.tt
@@ -1,5 +1,5 @@
/*
* Author: <%= maintainer %> <<%= maintainer_mail %>>
* Author: <%= maintainer %>
* Created at: <%= Time.now %>
*
*/
Expand Down
2 changes: 1 addition & 1 deletion pgxn_utils.gemspec
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.authors = ["Dickson S. Guedes"]
s.email = ["guedes@guedesoft.net"]
s.homepage = "http://github.com/guedes/pgxn-utils"
s.summary = %q{A PGXN set of tools to developers}
s.summary = %q{A PGXN set of tools to PostgreSQL extension's developers}
s.description = %q{A PGXN set of tools to help developers create and publish your PostgreSQL extensions without pain}

s.rubyforge_project = "pgxn_utils"
Expand Down
6 changes: 4 additions & 2 deletions spec/cli_spec.rb
Expand Up @@ -42,10 +42,12 @@
meta.should match(/"version": "#{expected_version}"/)
meta.should match(/"license": "postgresql"/)
meta.should match(/"release_status": "unstable"/)
meta.should match(/"#{expected_name} <#{expected_mail}>"/)
#TODO: I want define how split this from META
#meta.should match(/"#{expected_name} <#{expected_mail}>"/)
meta.should match(/"#{expected_name}"/)
meta.should match(/"file": "sql\/#{expected_extension}.sql"/)
meta.should match(/"docfile": "doc\/#{expected_extension}.md"/)
meta.should_not match(/"generated_by":/)
meta.should_not match(/"generated_by": #{expected_name}/)
meta.should match(/"tags": \[ "one","two","tree" \],/)

makefile = File.read("/tmp/#{expected_extension}/Makefile")
Expand Down

0 comments on commit d8f144e

Please sign in to comment.