xtm-utils/bin/xtminfo

83 lines
1.4 KiB
Text
Raw Permalink Normal View History

#!/usr/bin/env ruby
2010-11-08 12:07:09 +00:00
require 'optparse'
require 'xtmfile/header'
2010-11-08 12:07:09 +00:00
module XtmFile
class XtmInfo
class XtmInfoArgumentError < ArgumentError ; end
2010-11-08 12:07:09 +00:00
attr_reader :opts
2010-11-08 12:07:09 +00:00
def initialize args
@args = []
@input_xtm = nil
parse_command_line args
end
2010-11-08 12:07:09 +00:00
def parse_command_line args
@args = args.clone
@opts = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename $0} [options]\n"
2010-11-08 12:07:09 +00:00
opts.separator ""
opts.separator "Mandatory options"
2010-11-08 12:07:09 +00:00
opts.on("-i", "--input FILE", "Input XTM file") do |r|
@input_xtm = r
end
2010-11-08 12:07:09 +00:00
opts.separator ""
opts.separator "General options:"
2010-11-08 12:07:09 +00:00
opts.on("-h", "--help", "Show this help") do |h|
@help = h
end
opts.on("-v", "--verbose", "Show warnings too") do |v|
@verbose = v
end
opts.separator ""
2010-11-08 12:07:09 +00:00
end
end
def validate!
@opts.parse!
2010-11-08 12:07:09 +00:00
raise XtmInfoArgumentError, "No input XTM file specified!" if @input_xtm.nil?
end
2010-11-08 12:07:09 +00:00
def run
validate!
2010-11-08 12:07:09 +00:00
File.open( @input_xtm, "rb" ) do |io|
header = Header::read io
puts header.to_summary_string
end
2010-11-08 12:07:09 +00:00
end
def self.main args
xj = nil
begin
xj = XtmInfo.new args
xj.run
exit 0
rescue XtmInfoArgumentError => e
STDERR.puts "%s" % xj.opts
STDERR.puts "error: %s" % e.message
exit 1
rescue SystemExit => e
raise e
rescue Exception => e
STDERR.puts "error: %s" % e.message
STDERR.puts e.backtrace
exit 1
end
2010-11-08 12:07:09 +00:00
end
end
end
XtmFile::XtmInfo.main ARGV