def self.parse(args)
options = OpenStruct.new
options.verbose = false
OptionParser.new do |opts|
opts.banner = "Usage: cddb_parser [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-C", "--check", "check files only") do |c|
options.check = 1
end
fmt_list = (LIST_ABBREV.keys + LIST_CODES).join(',')
opts.on("-L", "--list [FMT]", LIST_ABBREV, LIST_CODES, "Select list format",
"(#{fmt_list})") do |fmt|
if options.check
STDERR.puts "error: cannot use -L and -C together"
exit 1
end
options.list = fmt.nil? ? 'all' : fmt
end
opts.on("-S", "--store DATABASE", "store info in database") do |s|
if options.check
STDERR.puts "Can't run store and check together"
exit 1
elsif options.list
STDERR.puts "Can't run list and store together"
exit 1
end
options.store = s
end
opts.separator ""
opts.separator "Store options:"
opts.on("-p", "--password PASSWORD", "database password") do |p|
unless options.store
STDERR.puts "Store option must be specified for password"
exit 1
end
options.password = p
end
opts.on("-u", "--user USER", "database username") do |u|
unless options.store
STDERR.puts "Store option must be specified for user"
exit 1
end
options.user = u
end
opts.separator ""
opts.separator "Helper options:"
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
options.verbose = v
end
opts.on_tail("--version", "Show version") do
puts OptionParser::Version.join('.')
exit
end
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
end.parse!
options.files = ARGV
if options.files.empty?
STDERR.puts "At least one CDDB file must be specified!"
exit 1
end
options
end