lib/sqld4r/sqld4r_options.rb in sqld4r-0.0.1 vs lib/sqld4r/sqld4r_options.rb in sqld4r-0.0.2
- old
+ new
@@ -47,10 +47,14 @@
opts.on( '--conf=/path/to/conffile', 'change conf file path($HOME/.sqld4r < conf < command line params)' ) do |p|
self["sqld4r_conf_path"] = p
end
+ opts.on( '--save=/save/to/xmlfile', 'save xml file path(../docs/sqldesigner.xml < conf < command line params)' ) do |p|
+ self["copy_sqld_to"] = p
+ end
+
opts.on( '--svn', 'Modify files with subversion. (Note: svn must be in path/for script/generate)') do
@@command_line_params["svn"] = true
end
opts.on( '--git', 'Modify files with git. (Note: git must be in path/for script/generate)') do
@@ -78,11 +82,11 @@
end
opts.on( '--skip-index', "Don't add index to migration files") do
@@command_line_params["skip-index"] = true
end
-
+
opts.on( '--verbose', 'provide extra output while running') do
@@command_line_params["verbose"] = true
end
opts.on( '--sudo', 'use sudo command') do
@@ -95,10 +99,18 @@
opts.on( '--logfile=/path/to/logfile', 'Set path to logfile. default is ../docs/sqld4r.log' ) do |p|
@@command_line_params["log_file"] = p
end
+ opts.on( '--command_list=/path/to/listfile', 'Set path to a command list for executing it before finish. default is $HOME/sqld4r_execute_commands' ) do |p|
+ @@command_line_params["command_list_path"] = p
+ end
+
+ opts.on( '--skip_command_list', "Don't execute commands on a command list" ) do
+ @@command_line_params["skip_command_list"] = true
+ end
+
opts.on( '--emulate', 'enable emulation mode' ) do
@@command_line_params["emulate"] = true
end
opts.separator ""
@@ -113,11 +125,11 @@
opts.on( '-v', '--version', 'display version information' ) do
puts "The model generator for SQLDesigner: #{@@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 execute_command_list' ) do
self["init"] = true
end
self["check"] = false
opts.on( '--check', 'check current variables' ) do
@@ -143,10 +155,11 @@
self.each_pair do |key, value| puts "#{key}:#{value}" end
exit
end
if self["init"] or "--init" == self["sqld_path"]
put_conf_file
+ put_commandlist_file
exit
end
self
end
@@ -182,10 +195,44 @@
rescue
puts "Warning:Could not open for writing. check parmitions."
end
end
+ # write a template command list file to command_list_path
+ def put_commandlist_file
+ # check put path
+ Sqld4r_options::error_with_show_usage "command list path is empty. set --command_list paramater." if self["command_list_path"].empty?
+
+ unless "y" == Readline.readline("Would a template file put to #{self["command_list_path"]}? [y/N] > ").downcase
+ puts "Set your command list path to --command_list paramater."
+ exit
+ end
+
+ begin
+ File.open(self["command_list_path"]) do |textfile|
+ # check overwrite?
+ exit unless "y" == Readline.readline("Overwrite? [y/N]").downcase
+ end
+ rescue
+ end
+
+ begin
+ File.open(self["command_list_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 executable commands:"
+ textfile.puts "rake db:migrate"
+ textfile.puts "capify ."
+ textfile.puts "# NOTE:recommend 'rake db:migrate' command to write here."
+ end
+ puts "Put template command list file to #{self["command_list_path"]}"
+ rescue
+ puts "Warning:Could not open for writing. check parmitions."
+ end
+ end
+
def self.error_with_show_usage(message)
puts "Error:" + message
Sqld4r_options::show_usage
exit(1)
end
@@ -205,23 +252,24 @@
# default values if not use .sqld4r file
def self.static_default_values
defaults = {}
defaults["sqld4r_conf_path"] = ENV["HOME"] + "/.sqld4r"
- defaults["copy_sqld_to"] = "../docs/sqldesigner.xml"
+ defaults["copy_sqld_to"] = "../../docs/sqldesigner.xml"
defaults["svn"] = false
defaults["git"] = false
defaults["skip-timestamps"] = false
defaults["skip-migration"] = false
defaults["skip-fixture"] = false
defaults["rspec"] = false
defaults["skip-relation"] = false
defaults["skip-index"] = false
- defaults["execute_command_list"] = ENV["HOME"] + "/.sqld4r_execute_commands"
+ defaults["command_list_path"] = ENV["HOME"] + "/sqld4r_execute_commands"
+ defaults["skip_command_list"] = false
defaults["verbose"] = false
defaults["sudo"] = false
defaults["logging"] = false
- defaults["log_file"] = "./sqld4r.log"
+ defaults["log_file"] = "../../docs/sqld4r.log"
defaults["emulate"] = false
defaults
end
# priority static < conf < command line params