#!/usr/bin/env ruby require 'pathname' root = Pathname.new(__FILE__).realpath.parent.parent $:.unshift root.join('lib') if $0 == __FILE__ require 'optparse' require 'oddb2xml' def help < false, :adr => false, :nonpharma => false, :extended => false, :compress_ext => nil, :format => :xml, :tag_suffix => nil, :debug => false, :ean14 => false, :skip_download=> false, :log => false, :percent => 0, } parser.on('-a v', '--append v', /^nonpharma$/) {|v| opts[:nonpharma] = true } parser.on('-c v', '--compress v', /^tar\.gz|zip$/){|v| opts[:compress_ext] = v } parser.on('-e [x]', '--extended [x]') {|v| opts[:extended] = true opts[:nonpharma] = :true opts[:price] = :zurrose opts[:percent] = v ? v.to_i : 0 } parser.on('-f v', '--format v', /^xml|dat$/) {|v| opts[:format] = v.intern } parser.on('-o v', '--option v', /^fi$/) {|v| opts[:fi] = true } parser.on('-i v', '--include v', /^ean14$/) {|v| opts[:ean14] = true } parser.on('-t v', '--tag-suffix v', /^[A-z0-9]*$/i) {|v| opts[:tag_suffix] = v.upcase } parser.on('-x v', '--context v', /^addr(ess)*$/i){|v| opts[:address] = true } parser.on('-p v', '--price v', /^zurrose$/) {|v| opts[:price] = v.intern } parser.on('--skip-download') {|v| opts[:skip_download] = true } parser.on('--log') {|v| opts[:log] = :true } parser.on_tail('-h', '--help') { puts help; exit } args = ARGV.dup begin parser.parse!(args) rescue OptionParser::MissingArgument, OptionParser::InvalidArgument, OptionParser::InvalidOption puts help exit end # TEMP if path = args.first opts[:transfer_dat] = path end startTime = Time.now ui = Oddb2xml::Cli.new(opts) begin if opts[:format] == :xml opts[:ean14] = true # force end #puts opts if opts[:debug] if RUBY_VERSION.to_f < 1.9 message = <<-MES Once you find some time, please upgrade your Ruby to 1.9.3 ;) then you will not see anymore warnings MES warn message end ui.run rescue Interrupt exit end diff = (Time.now-startTime).to_i puts "#{Time.now}: #{__LINE__} done. Took #{diff} seconds"; $stdout.sync