#!/usr/bin/env ruby require 'optionparser' APP = File.basename(__FILE__) commands = { "analyze" => { :bin => "analyze", :description => "Analyze logged SQL queries" }, "watch" => { :bin => "watch.rb", :description => "Log queries from Rails command" } } global = OptionParser.new do |opts| opts.banner = "usage: #{APP} [--help] []" opts.separator "" opts.separator "These are the commands available:" commands.each do |name,info| opts.separator " #{name} #{info[:description]}" end opts.separator "" opts.separator "See #{APP} --help to read about a specific command." opts.separator "" end global.order! command = ARGV.shift if command.nil? puts global.to_s exit end if !commands.key?(command) puts "#{APP}: '#{command}' is not a '#{APP}' command. See '#{APP} --help'." exit 1 end path = "#{File.dirname(__FILE__)}/#{commands[command][:bin]}" Kernel.exec(path, *ARGV)