require 'getoptlong'
class Options
  def initialize ( *args)
    @setopts = Hash.new
    a=Array.new
    @cmdline=args.shift
    @options=args.clone
    until args.empty?
      a.push(args.shift)
      args.shift
    end
    begin
      GetoptLong.new(*a).each { |opt, arg|
        @setopts.store(opt,(arg ? arg : true))
      }
    rescue GetoptLong::InvalidOption
      usage
      exit -1
    end

  end

  def [](key)
    @setopts[key]
  end

  def usage
    puts @cmdline+"\n"
    i =0
    while i < @options.length
      printf("  %-20s :   %s\n", @options[i][0..-2].join(', '), @options[i+1])
      i+=2
    end

  end
end

