#!/usr/bin/ruby # coding: utf-8 # NB: When testing locally, you can run this as: # # ruby -Ilib bin/onix_extract_codelists [options] xsd dir require 'optparse' def parse_options options = {} optparse = OptionParser.new do |parser| parser.banner = [ "Usage: onix_extract_codelists [options] xsd_path output_dir_path", "", " eg: onix_extract_codelists ONIX_BookProduct_CodeLists.xsd support/codes" ].join("\n") options[:format] = :tsv parser.on("-f", "--format FMT", "Write to format (TSV or Ruby)") do |fmt| options[:format] = fmt.downcase.to_sym end parser.on("-h", "--help", "Display this usage information") do puts parser exit end end optparse.parse! unless ARGV.size == 2 puts optparse exit(1) end options end options = parse_options require "cacofonix" extractor = Cacofonix::CodeListExtractor.new(ARGV.shift, options[:format]) extractor.run(ARGV.shift)