# usage: tap {options} [args] # # examples: # tap generate root /path/to/root # generates a root dir # tap run taskname --option input # runs the 'taskname' task # # help: # tap help # prints this help # tap command --help # prints help for 'command' require File.join( File.dirname(__FILE__), "../lib/tap.rb") require "tap/script" app = Tap::App.instance script = Tap::Script.instance begin # configure the app to tap.yml if it exists config_file = Tap::Script.config_filepath(Dir.pwd) config = Tap::Script.read_config(config_file) script.configure_app(config) rescue(Exception) # catch errors and exit gracefully # (errors usu from gem loading errors) puts "Configuration error: #{$!.message}" puts "Check #{config_file} configurations" exit(1) end # alert the user to the root directory if it's not Dir.pwd unless app.options.quiet || app.root == File.expand_path(Dir.pwd) puts "root: #{app.root}" end # # run before script # begin eval(script.config.before.to_s) rescue puts "Error in before script." if app.options.debug raise else puts $!.message exit(1) end end begin available_commands = script.config.scripts command = ARGV.shift case command when "--help", "-h", "help", "?", nil # give some help puts Tap::Script.usage(__FILE__) puts puts "available commands:" commands = available_commands.keys commands.unshift("help") print " " puts commands.sort.join("\n ") puts puts "version #{Tap::VERSION} -- #{Tap::HOMEPAGE}" else if available_commands.has_key?(command) # run the script, if it exists load available_commands[command] else puts "Unknown command: '#{command}'" puts "Type 'tap help' for usage information." end end rescue if app.options.debug raise else puts $!.message puts "Type 'tap #{command} --help' for usage information." end end # # run after script # begin eval(script.config.after.to_s) rescue puts "Error in after script." if app.options.debug raise else puts $!.message exit(1) end end