class ArgParser
Public Class Methods
parse(args)
click to toggle source
Returns a structure describing the options.
# File lib/argparser.rb, line 37 def self.parse(args) # The options specified on the command line will be collected in <b>options</b>. # We set default values here. options = OpenStruct.new options.debug = false options.template = $DEFAULT_TEMPLATE options.mapping = $DEFAULT_MAPPING options.default_mapping = true options.default_template = true options.output = "./dbf2text_out" options.delimiter = $DELIMITER op = OptionParser.new do |opts| opts.banner = Translating::trl("Usage") << ":\t" << Translating::trl("ruby %s.rb [dbf-file] [options]") %($APPNAME) << "\n\t" << Translating::trl("or %s [Common options]") %($APPNAME) opts.separator "" opts.separator Translating::trl("Specific options") << ':' opts.on('-' << Translating::trl("d"), '--' << Translating::trl("debug [true|FALSE]"), Translating::trl("Switch on debug-mode. Will generate log-messages during processing")) do |deb| options.debug = (deb && deb.chomp.downcase == 'false' ? nil : true) end opts.on('-' << Translating::trl("m"), '--' << Translating::trl("mapping [MAPPING-FILE]"), Translating::trl( "Use the field-mapping as specified in this MAPPING-FILE.")) do |mapping| options.mapping = mapping options.default_mapping = false end opts.on('-' << Translating::trl("t"), '--' << Translating::trl("template [TEMPLATE-FILE]"), Translating::trl( "Use the specified file as template.")) do |template| options.template = template options.default_template = false end opts.on('-' << Translating::trl("o"), '--' << Translating::trl("output [FILE-NAME]"), Translating::trl("Write the result to this file.")) do |output| options.output = output end opts.on('-' << Translating::trl("f"), '--' << Translating::trl("delimiter"), Translating::trl("The given symbol marks fields in the template file (default is %s).") %($DELIMITER)) do |delim| options.delimiter = delim end =begin # This is for later. The evaluation of the file-content may be allocated to the # Configuration singleton, as it does not mean a lot of I/O nor does it imply # much management. opts.on("-c", "--config [CONFIG FILE]", "Read alternative configuration from this file") do |conf| $LOG.debug("config-file should be #{conf}") if $LOG options.config = File.expand_path(conf ) end opts.on("-g", "--generic [CONFIG FILE]", "Write generic configuration options to this file") do |file| options.generic = File.expand_path(file ) end =end opts.separator "" opts.separator Translating::trl("Common options") << ':' # No argument, shows at tail. This will print an options summary. opts.on_tail(Translating::trl("-h"), Translating::trl("--help"), Translating::trl("Show this message") ) do puts opts exit true end opts.on_tail(Translating::trl("-v"), Translating::trl("--version"), Translating::trl("Show version and program information") ) do puts "\t#{$APPNAME}" puts "\t© #{$YEARS}, #{$AUTHOR} <#{$AUTHOR_MAIL}>" exit true end end op.parse!(args) options end