Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added option parsing and common options

Added --template command line option

Added --configdir command line option

Removed .gemspec

Added CHANGELOG.rdoc

Updated README.rdoc
  • Loading branch information...
commit 81fd57d051382429fd9d27914e3680022a7acf05 1 parent 468bb90
@jamtur01 jamtur01 authored
View
28 .gemspec
@@ -1,28 +0,0 @@
-require 'ftools'
-require 'rake'
-require 'templater'
-require File.dirname(__FILE__)+'/lib/scaffold.rb'
-
-GEM_FILES = FileList[
- '[A-Z]*',
- 'bin/**/*',
- 'lib/**/*',
- 'spec/**/*',
- 'templates/**/**'
-]
-
-Gem::Specification.new do |spec|
- spec.platform = Gem::Platform::RUBY
- spec.name = 'scaffold'
- spec.files = GEM_FILES.to_a
- spec.executables = 'scaffold'
- spec.version = Scaffold::VERSION
- spec.add_dependency('templater', '>= 0.5.0')
- spec.summary = 'Scaffold is a templating tool for Puppet'
- spec.description = 'Scaffold allows you to create basic Puppet configuration, modules, nodes, classes, functions and types.'
- spec.author = 'James Turnbull'
- spec.email = 'james@lovedthanlost.net'
- spec.homepage = 'http://github.com/jamtur01/puppet-scaffold'
- spec.rdoc_options = ["--main", "README.rdoc"]
- spec.require_paths = ["lib"]
-end
View
20 CHANGELOG.rdoc
@@ -0,0 +1,20 @@
+Puppet Scaffold
+===============
+
+0.0.3
+-----
+
+ - Added --template command line option
+ - Added --configdir command line option
+ - Added optparse
+ - Removed .gemspec and included this in Rakefile
+
+0.0.2
+-----
+
+ - Fixed bug with template directory
+
+0.0.1
+-----
+
+ - Initial release
View
22 README.rdoc
@@ -20,26 +20,32 @@ Creates:
== SYNOPSIS:
+Use the --template option to specify the type of template you want to create.
+
Create a module:
- $ scaffold module module_name
+ $ scaffold --template=module module
Create a node:
- $ scaffold node node_name
+ $ scaffold --template=node node
Create a class:
- $ scaffold class module_name class_name
+ $ scaffold --template=class module class
Create a definition:
- $ scaffold define module_name define_name
+ $ scaffold --template=define module define
Create a function:
- $ scaffold function module_name function_name function_type
+ $ scaffold --template=function module function type
Create a type/provider:
- $ scaffold type module_name type_name
+ $ scaffold --template=type module type
Create Puppet configuration:
- $ scaffold puppet
+ $ scaffold --template=puppet
+
+Puppet configuration is specified in the directory specified in the Puppet confdir variable but you can override this with the --configdir option.
+
+ $ scaffold --template=puppet --configdir=/opt/puppet
== REQUIREMENTS:
@@ -52,7 +58,7 @@ Create Puppet configuration:
== LICENSE:
-(The MIT License)
+The MIT License
Copyright (c) 2010 James Turnbull
View
35 Rakefile
@@ -1,16 +1,37 @@
require 'rubygems'
-require 'newgem/tasks'
+require 'rake'
+require 'rake/gempackagetask'
require 'fileutils'
-require 'templater'
-require File.dirname(__FILE__)+'/lib/scaffold.rb'
+require 'ftools'
-version = Scaffold::VERSION
+version = File.read('lib/scaffold.rb')[/VERSION *= *'(.*)'/,1] or fail "Couldn't find Scaffold version"
-desc "Build gem"
-task :build do
- system "gem build .gemspec"
+GEM_FILES = FileList[
+ '[A-Z]*',
+ 'bin/**/*',
+ 'lib/**/*',
+]
+
+spec = Gem::Specification.new do |spec|
+ spec.name = 'scaffold'
+ spec.files = GEM_FILES.to_a
+ spec.executables = 'scaffold'
+ spec.version = version
+ spec.add_dependency('templater', '>= 0.5.0')
+ spec.summary = 'Scaffold is a templating tool for Puppet'
+ spec.description = 'Scaffold allows you to create basic Puppet configuration, modules, nodes, classes, functions and types.'
+ spec.author = 'James Turnbull'
+ spec.email = 'james@lovedthanlost.net'
+ spec.homepage = 'http://github.com/jamtur01/puppet-scaffold'
+ spec.rdoc_options = ["--main", "README.rdoc"]
+ spec.require_paths = ["lib"]
end
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = true
+ pkg.need_tar = true
+ end
+
desc "Release gem to Gemcutter"
task :release => :build do
system "gem push scaffold-#{version}.gem"
View
6 TODO.rdoc
@@ -1,6 +1,4 @@
= scaffold TODO
-* Create generators for:
- - Check for presence of modules before creation
- - Tests
-
+- Check for presence of modules before creation
+- Tests
View
87 bin/scaffold
@@ -1,21 +1,80 @@
#!/usr/bin/env ruby
require 'rubygems'
-require 'puppet'
-require 'templater'
-require File.dirname(__FILE__)+'/../lib/scaffold.rb'
+require 'optparse'
+require 'scaffold'
-Puppet.parse_config
+TEMPLATES = %w[puppet module node class define function type]
-case ARGV[0]
- when 'puppet', 'node'
+options = {}
+
+optparse = OptionParser.new do |opts|
+ # Set a banner, displayed at the top
+ # of the help screen.
+ opts.banner = 'Usage: scaffold [options] --template="template" options ...'
+
+ opts.separator ''
+ opts.separator 'Configuration options:'
+
+ options[:configfile] = nil
+ opts.on( '-f', '--configfile=FILE', 'Use file as configuration file') do |file|
+ options[:configfile] = file
+ end
+
+ options[:configdir] = nil
+ opts.on( '-c', '--configdir=DIRECTORY', 'Specify the location of your Puppet configuration directory') do |confdir|
+ options[:configdir] = confdir
+ end
+
+ options[:templatedir] = nil
+ opts.on( '--templatedir=DIRECTORY', 'Use directory as template loation') do |templatedir|
+ options[:templatedir] = templatedir
+ end
+
+ options[:template] = nil
+ opts.on( '--template=TEMPLATE', TEMPLATES, 'Template to create') do |template|
+ options[:template] = template
+ end
+
+ opts.separator ""
+ opts.separator "Common options:"
+
+ opts.on_tail('-v', '--version', 'Show version') do
+ puts Scaffold::VERSION
+ exit
+ end
+
+ opts.on_tail('-h', '--help', 'Display this screen' ) do
+ puts opts
+ exit
+ end
+end
+
+begin
+ optparse.parse!
+ mandatory = [:template]
+ missing = mandatory.select{ |param| options[param].nil? }
+ if not missing.empty?
+ puts "Missing options: #{missing.join(', ')}"
+ puts optparse
+ exit
+ end
+rescue OptionParser::InvalidArgument, OptionParser::InvalidOption, OptionParser::MissingArgument
+ puts $!.to_s
+ puts optparse
+ exit
+end
+
+if options[:template] == 'puppet'
+ if options[:configdir]
+ dir = options[:configdir]
+ else
dir = Puppet[:confdir]
- puts "#{dir}"
- Scaffold::Generator.run_cli(dir, 'scaffold', Scaffold::VERSION, ARGV)
- when 'module', 'class', 'define'
- dir = Puppet[:modulepath].split(':')
- Scaffold::Generator.run_cli(dir[0], 'scaffold', Scaffold::VERSION, ARGV)
- when 'function', 'type'
- dir = Puppet[:modulepath].split(':')
- Scaffold::Generator.run_cli(dir[0], 'scaffold', Scaffold::VERSION, ARGV)
+ end
+else
+ dir = Puppet[:modulepath].split(':')
end
+
+ARGV.unshift(options[:template])
+
+Scaffold::Generator.run_cli dir.to_s, 'scaffold', Scaffold::VERSION, ARGV
View
29 lib/scaffold.rb
@@ -2,11 +2,38 @@
require 'rubygems'
require 'templater'
-
+require 'puppet'
require path + 'generator'
module Scaffold
+ Puppet.parse_config
+
VERSION = '0.0.2'
+ def config
+ config = {}
+
+ configfile = options[:configfile] || Puppet[:confdir] + 'scaffold.conf'
+
+ File.foreach(configfile) do |line|
+ line.strip!
+ # Skip comments and whitespace
+ if (line[0] != ?# and line =~ /\S/ )
+ i = line.index('=')
+ if (i)
+ config[line[0..i - 1].strip] = line[i + 1..-1].strip
+ else
+ config[line] = ''
+ end
+ end
+ end
+
+ # Print it out
+ config.each do |key, value|
+ print key + " = " + value
+ print "\n"
+ end
+ end
+
end
View
16 lib/scaffold/generator.rb
@@ -9,13 +9,13 @@ module Generator
##
class ModuleGenerator < Templater::Generator
desc <<-DESC
- Create an empty Puppet module
+ Create an empty Puppet module. You must specify the name of the module.
DESC
first_argument :module_name, :required => true, :desc => "Your module name."
def self.source_root
- File.join(File.dirname(__FILE__), 'templates/module')
+ File.join(File.dirname(__FILE__), 'templates/module')
end
# Create all subsdirectories
@@ -53,7 +53,7 @@ def self.source_root
class NodeGenerator < Templater::Generator
desc <<-DESC
- Generate a basic Puppet node
+ Generate a basic Puppet node. You must specify the name of the node.
DESC
first_argument :node_name, :required => true, :desc => "Your node name."
@@ -76,7 +76,7 @@ def self.source_root
class ClassGenerator < Templater::Generator
desc <<-DESC
- Create a Puppet class.
+ Create a Puppet class. You must specify the name of the module to create the class in and the name of the class.
DESC
first_argument :module_name, :required => true, :desc => "The module that contains the class"
@@ -94,7 +94,7 @@ def self.source_root
class DefineGenerator < Templater::Generator
desc <<-DESC
- Create a Puppet definition.
+ Create a Puppet definition. You must specify the name of the module to create the definition in and the name of the definition.
DESC
first_argument :module_name, :required => true, :desc => "The module that contains the definition"
@@ -112,7 +112,7 @@ def self.source_root
class FunctionGenerator < Templater::Generator
desc <<-DESC
- Create a Puppet function.
+ Create a Puppet function. Specify the name of the module, the name of the function and the type of the function, either statement or rvalue. Generator defaults to statement.
DESC
first_argument :module_name, :required => true, :desc => "The module that contains the function"
@@ -136,7 +136,7 @@ def self.source_root
class TypeGenerator < Templater::Generator
desc <<-DESC
- Create a Puppet type and provider.
+ Create a Puppet type and provider. You must specify the module to create the type and provider in and the name of the type to be created.
DESC
first_argument :module_name, :required => true, :desc => "The module that contains the type"
@@ -168,7 +168,7 @@ def self.source_root
class PuppetGenerator < Templater::Generator
desc <<-DESC
- Generate a basic Puppet configuration - specify the location of your Puppet configuration directory, for example /etc/puppet.
+ Generate a basic Puppet configuration.
DESC
def self.source_root
Please sign in to comment.
Something went wrong with that request. Please try again.