#!/usr/bin/env ruby require 'getoptlong' require 'reap/reap' # dislpay the help information def show_help puts <<-HERE reap v#{Reap::VERSION} USAGE: reap [options...] [arguments...] COMMANDS: help Displays this help information. HERE Reap::Task.registry.each do |t| puts " #{t.task}" puts " #{t.desc}\n\n" end puts <<-HERE OPTIONS: -v --verbose Provides extra verbose processing information. -u --use Use the specified configuration file rather than the default 'Reapfile'. -p --pretend (NOT YET IMPLEMENTED) Pretend, just to see what would happen, but don't actually do anything. --version Display the current version. --help Display this help information. HERE end # START OF EXECUTION opts = GetoptLong.new( [ "-v", "--verbose", GetoptLong::NO_ARGUMENT ], [ "-p", "--pretend", GetoptLong::NO_ARGUMENT ], [ "-d", "--debug", GetoptLong::NO_ARGUMENT ], [ "-u", "--use", GetoptLong::REQUIRED_ARGUMENT ], [ "--version", GetoptLong::NO_ARGUMENT ], [ "--help", GetoptLong::NO_ARGUMENT ] ) cmd = ARGV[0] args = ARGV[1..-1] config = nil opts.each do |o, a| case o when '-v' $VERBOSE = true when '-p' $PRETEND = true when '-u' config = a when '-d' $DEBUG = true when '--help' cmd = 'help' when '--version' cmd = 'version' end end cmd = cmd.downcase if cmd if cmd == nil or cmd == 'help' show_help exit 0 end if cmd == 'version' puts Reap::VERSION exit 0 end runner = Reap::Runner.new( config ) if runner.task?( cmd.downcase.to_sym ) cmd = cmd.to_s.downcase.to_sym runner.call( cmd, *args ) else puts "Unknown command. Try 'reap help' for assitance." exit 0 end