Class: ArgParser

Inherits:
Object
  • Object
show all
Extended by:
Logging, Translating
Defined in:
lib/argparser.rb

Constant Summary collapse

@@log =
init_logger()

Class Method Summary collapse

Methods included from Logging

init_logger, log_level=, log_target=

Methods included from File_Checking

#file_check, file_check

Methods included from Translating

language, trl, trl

Class Method Details

.parse(args) ⇒ Object

Returns a structure describing the options.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/argparser.rb', line 39

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.table_name = false

	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 [FILE.sqlite]"), trl( "SQLite-file to read.")) do |source|
			options.source = source
		end

		opts.on('-' << trl("t"), '--' << trl("target [FILE(0...n).dbf]"), trl( "Name for the dBase-files (1 per table) to be written.")) do |target|
			options.target = target
		end

		opts.on('--' << trl("time [list]"), trl( "A list of space-separated fields (table-columns) which shall be handled as timestamp values.")) do |list|
			options.time = list.gsub(/[,;]/, '').split
		end
		
		opts.on('--' << trl("dates [list]"), trl( "A list of space-separated fields (table-columns) which shall be handled as date-time values.")) do |list|
			options.datetime = list.gsub(/[,;]/, '').split
		end

		opts.on('-' << trl('o'), trl("--orig [PATH]"), trl('Use the table-name as file-name for the DBF-result, store output in PATH')) do |path|
			options.table_name = true
			options.out_dir = path
		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