#!/usr/bin/env ruby require 'optionparser' APP = File.basename(__FILE__) commands = { "explain" => "Generate a report from logged SQL queries", "check" => "Check staged files for query problems", } 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}" 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.join(File.dirname(__FILE__), command) Kernel.exec(path, *ARGV)