class ArgParser
Public Class Methods
parse(args)
click to toggle source
Returns a structure describing the options.
# File lib/argparser.rb, line 39 def self.parse(args) # The options specified on the command line will be collected in # <b>options</b>. No defaults. Most options are optional and do not # have to be set at all. # The others must be named for each transformation or be set in the # configuration-file. options = OpenStruct.new op = OptionParser.new do |opts| opts.banner = "\n" << trl("Usage") << ":\t" << $APPNAME.dup << ' ' << trl("-s [SQLite-file] [options]") << "\n\t" << trl("or %s [Common options]") %($APPNAME) opts.separator "" opts.separator trl("Specific options") << ':' opts.on('-' << trl("s"), '--' << trl("source [PATH]"), trl( "SQLite-file to read.")) do |source| options.source = source end opts.on('-' << trl('c'), '--' << trl("config [PATH]"), trl('Configuration file for this transformation')) do |config| options.config = config end opts.on('-' << trl('n'), '--' << trl("name [TABLE]"), trl('The name of the table from the SQLite-database to convert')) do |name| options.name = name end opts.on('-' << trl("t"), '--' << trl("target [PATH]"), trl( "Path to the dBase-file to be written.")) do |target| options.target = target end opts.on('-' << trl("l"), '--' << trl("list"), trl( "Show the list of available tables and exit")) do |target| options.list = true end opts.on('-' << trl('o'), '--' << trl("out [PATH]"), trl('Use the table-name as file-name for the DBF-result, store output in PATH')) do |path| options.name_like_table = true options.out = path end opts.on('--' << trl("time [list]"), trl( "Fields (table-columns) which shall be handled as timestamp values.")) do |list| options.time = list.gsub(/[,;]/, '').split end opts.on('--' << trl("date [list]"), trl( "Fields (table-columns) which shall be handled as date-time values.")) do |list| options.datetime = list.gsub(/[,;]/, '').split 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 trl("Common options") << ':' # No argument, shows at tail. This will print an options summary. # opts.on_tail(trl("-d"), trl("--debug"), trl("Show debug-messages") ) do options.debug = true @@log.level = Logger::DEBUG end opts.on_tail(trl("-h"), trl("--help"), trl("Show this message") ) do puts opts exit true end opts.on_tail(trl("-v"), trl("--version"), trl("Show version and program information") ) do puts "\t#{$APPNAME}" puts "\t© #{$YEARS}, #{$AUTHORS.join(', ')}" exit true end end begin op.parse!(args) rescue OptionParser::ParseError => er msg = trl("ERROR! Unsuitable or incomplete program-arguments") << (": %s" %er.message ) puts msg puts trl("Start this program with parameter -h or --help to see the usage-message.") exit false end options end