#!/usr/bin/env ruby
require 'rhc/coverage_helper'

def get_args
  ARGV.shift
  args = ""
  ARGV.each do|a|
    if ( a.to_s.strip.length == 0 || a.to_s.strip.match(/\s/) ); a = "'#{a}'" end
    args += " #{a}"
  end
  args
end

begin
  Signal.trap("PIPE", "EXIT") if Signal.list["PIPE"]

  retcode = begin
    require 'rhc/cli'
    RHC::CLI.set_terminal
    RHC::CLI.start(ARGV)
  rescue Interrupt
    puts "Interrupted"
    128 + 2
  rescue SystemExit => e
    puts
    e.status
  end

  if retcode == nil
    retcode = 1

    # return codes for uncaught signals are 128 + the signal code
    retcode = 128 + $?.termsig if $?.signaled? and !$?.termsig.nil?
  end

  exit retcode
end
