Adds general options like -h and --quiet. Usually don't override.
# File lib/rails_generator/options.rb, line 119 def add_general_options!(opt) opt.separator '' opt.separator 'Rails Info:' opt.on('-v', '--version', 'Show the Rails version number and quit.') opt.on('-h', '--help', 'Show this help message and quit.') { |v| options[:help] = v } opt.separator '' opt.separator 'General Options:' opt.on('-p', '--pretend', 'Run but do not make any changes.') { |v| options[:pretend] = v } opt.on('-f', '--force', 'Overwrite files that already exist.') { options[:collision] = :force } opt.on('-s', '--skip', 'Skip files that already exist.') { options[:collision] = :skip } opt.on('-q', '--quiet', 'Suppress normal output.') { |v| options[:quiet] = v } opt.on('-t', '--backtrace', 'Debugging: show backtrace on errors.') { |v| options[:backtrace] = v } opt.on('-c', '--svn', 'Modify files with subversion. (Note: svn must be in path)') do options[:svn] = {} `svn status`.each_line do |line| options[:svn][line.chomp[7..-1]] = true end end opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do options[:git] = {:new => {}, :modified => {}} `git status`.each_line do |line| options[:git][:new][line.chomp[14..-1]] = true if line =~ /new file:/ options[:git][:modified][line.chomp[14..-1]] = true if line =~ /modified:/ end end end
Override to add your options to the parser:
def add_options!(opt) opt.on('-v', '--verbose') { |value| options[:verbose] = value } end
# File lib/rails_generator/options.rb, line 115 def add_options!(opt) end
Convenient access to class default options.
# File lib/rails_generator/options.rb, line 61 def default_options self.class.default_options end
Merge together our instance options. In increasing precedence:
default_options (class default options) options (instance options) runtime_options (provided as argument) mandatory_options (class mandatory options)
# File lib/rails_generator/options.rb, line 70 def full_options(runtime_options = {}) self.class.full_options(options.merge(runtime_options)) end
Convenient access to class mandatory options.
# File lib/rails_generator/options.rb, line 56 def mandatory_options self.class.mandatory_options end
Parse arguments into the options hash. Classes may customize parsing behavior by overriding these methods:
#banner Usage: ./script/generate [options] #add_options! Options: some options.. #add_general_options! General Options: general options..
# File lib/rails_generator/options.rb, line 81 def parse!(args, runtime_options = {}) self.options = {} @option_parser = OptionParser.new do |opt| opt.banner = banner add_options!(opt) add_general_options!(opt) opt.parse!(args) end return args ensure self.options = full_options(runtime_options) end
Raise a usage error. Override usage_message to provide a blurb after the option parser summary.
# File lib/rails_generator/options.rb, line 98 def usage(message = usage_message) raise UsageError, "#{@option_parser}\n#{message}" end
Generated with the Darkfish Rdoc Generator 2.