#!/usr/bin/env ruby # XXX What can go wrong with this loading approach? libdir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib")) if File.directory?(libdir) and File.exists?(File.join(libdir, "automateit.rb")) $LOAD_PATH.unshift(libdir) end require 'rubygems' require 'logger' require 'optparse' require 'automateit' include AutomateIt::Constants OptionParser.new do |parser| PROG = File.basename($0) opts = {} parser.banner = < e msg = nil if opts[:friendly_exceptions] != false and e.is_a?(AutomateIt::Error) # Friendly message msg = PERROR+e.message msg << "\n\n"+PNOTE+"Use 'automateit --trace' to see complete backtrace" else # Raw backtrace puts PERROR+"AutomateIt error trace:" stack = e.backtrace.clone msg = "#{stack.shift}: #{e.message} (#{e.exception.class})}"; for line in stack msg << "\n "+line end end puts msg exit 1 rescue SysExit => e # Don't display errors when exit gets called end if optscopy[:create] or optscopy[:eval] or argscopy.size > 0 exit rv ? 0 :1 else # CTRL-D ends the line prematurely, so add a newline puts end end