lib/rocketstarter/rocket_starter_options.rb in rocketstarter-0.0.1 vs lib/rocketstarter/rocket_starter_options.rb in rocketstarter-0.0.2
- old
+ new
@@ -2,21 +2,21 @@
require "yaml"
require "readline"
class Rocket_starter_options < Hash
- @@version = [ 0, 0, 1 ]
+ @@version = Rocketstarter::VERSION::STRING
@@product_name = "rocket_starter"
@@command_line_params = {}
def initialize
super()
# default values
self[:project] = ""
- self[:rocket_starter_conf_path] = ""
+ self[:rocket_starter_conf_path] = ENV["HOME"] + "/.rocketst_starter"
self[:rocket_starter_conf_path] = ENV['ROCKET_STARTER_CONF'] unless ENV['ROCKET_STARTER_CONF'].nil?
self[:init] = false
self.merge(Rocket_starter_options::static_default_values)
end
@@ -27,11 +27,11 @@
@@opts = OptionParser.new do |opts|
opts.banner = "Usage: #{@@product_name} project-name [options]"
opts.separator "Usage: #{@@product_name} --init [options]"
opts.separator "Usage: #{@@product_name} --check [options]"
- opts.separator "version #{@@version.join('.')}"
+ opts.separator "version #{@@version}"
opts.separator ""
opts.separator "Useful Options:"
opts.separator ""
@@ -93,10 +93,18 @@
opts.on( '--externals', 'use svn:externals for plugins' ) do
@@command_line_params[:external] = true
end
+ opts.on( '--createdb', 'execute rake db:create:all at last' ) do
+ @@command_line_params[:createdb] = true
+ end
+
+ opts.on( '--dbpassword', 'write password to config/database.yml file' ) do |p|
+ @@command_line_params[:dbpassword] = p
+ end
+
opts.on( '--emulate', 'enable emulation mode' ) do
@@command_line_params[:emulate] = true
end
opts.separator ""
@@ -107,15 +115,15 @@
puts opts
exit
end
opts.on( '-v', '--version', 'display version information' ) do
- puts "Ruby on Rails environment setup tool: #{@@product_name} version #{@@version.join('.')}"
+ puts "Ruby on Rails environment setup tool: #{@@product_name} version #{@@version}"
exit
end
- opts.on( '--init', 'setup a template of conf file' ) do
+ opts.on( '--init', 'setup a template of conf file and plugin list file' ) do
self[:init] = true
end
self[:check] = false
opts.on( '--check', 'check current variables' ) do
@@ -139,10 +147,11 @@
self.each_pair do |key, value| puts "#{key}:#{value}" end
exit
end
if self[:init] or "--init" == self[:project]
put_conf_file
+ put_pluginlist_file
exit
end
self
end
@@ -173,10 +182,44 @@
puts "Put template yaml file to #{self[:rocket_starter_conf_path]}"
rescue
puts "Warning:Could not open for writing. check parmitions."
end
end
+
+ # write a template plugin list file to :pluginlist_path
+ def put_pluginlist_file
+ # check put path
+ Sqld4r_options::error_with_show_usage "plugin list path is empty. set --pluginlist_path paramater." if self[:pluginlist_path].empty?
+
+ unless "y" == Readline.readline("Would a template of plugin list file put to #{self[:pluginlist_path]}? [y/N] > ").downcase
+ puts "Set your command list path to --pluginlist_path paramater."
+ exit
+ end
+
+ begin
+ File.open(self[:pluginlist_path]) do |textfile|
+ # check overwrite?
+ exit unless "y" == Readline.readline("Overwrite? [y/N]").downcase
+ end
+ rescue
+ end
+
+ begin
+ File.open(self[:pluginlist_path], "w") do |textfile|
+ textfile.puts "# command list file for executing it before finish"
+ textfile.puts ""
+ textfile.puts "# <- this line is comment."
+ textfile.puts "# next line is plugin URI:"
+ textfile.puts "http://svn.cardboardrocket.com/paginating_find"
+ textfile.puts "http://svn.techno-weenie.net/projects/plugins/attachment_fu/"
+ textfile.puts "http://svn.s21g.com/public/rails/plugins/annotate_models_with_index/"
+ end
+ puts "Put template of plugin list file to #{self[:pluginlist_path]}"
+ rescue
+ puts "Warning:Could not open for writing. check parmitions."
+ end
+ end
def self.error_with_show_usage(message)
puts "Error:" + message
Rocket_starter_options::show_usage
exit(1)
@@ -204,26 +247,29 @@
defaults[:database] = ""
defaults[:ignoredatabase] = false
defaults[:verbose] = false
defaults[:sudo] = false
defaults[:logging] = false
- defaults[:log_file] = "./rocket_starter.log"
+ defaults[:log_file] = ENV["HOME"] + "/rocket_starter.log"
defaults[:skip_netbeans] = false
- defaults[:pluginlist_path] = "./useful_plugins"
+ defaults[:pluginlist_path] = ENV["HOME"] + "/useful_plugins"
defaults[:skip_plugins] = false
defaults[:rapt] = false
defaults[:external] = false
+ defaults[:createdb] = false
+ defaults[:dbpassword] = ""
defaults[:emulate] = false
defaults
end
# priority static < conf < command line params
def marge_values
conf_params = {}
# can open?
begin
File::open(self[:rocket_starter_conf_path]) do |conf_file|
- conf_params = YAML.load(conf_file.read)
+ temp = YAML.load(conf_file.read)
+ conf_params = temp if temp
end
rescue
end
self.merge!(conf_params.merge!(@@command_line_params))
end