forked from jamtur01/puppet-scaffold
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
8 changed files
with
173 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters