bin/tap in tap-0.8.0 vs bin/tap in tap-0.9.0
- old
+ new
@@ -1,31 +1,62 @@
+#!/usr/local/bin/ruby
# usage: tap <command> {options} [args]
#
# examples:
-# tap generate root /path/to/root # generates a root dir
+# tap generate 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"
+# setup environment
+env = Tap::Env.instance
app = Tap::App.instance
-script = Tap::Script.instance
+env.logger = app.logger
+if ARGV.delete("-d-")
+ env.debug_setup
+end
+
+before = nil
+after = nil
+
+def handle_error(err)
+ case
+ when $DEBUG
+ puts err.message
+ puts
+ puts err.backtrace
+ when Tap::App.instance.debug? then raise err
+ else puts err.message
+ end
+end
+
+# configure the app to tap.yml if it exists
+default_config_file = File.expand_path( Tap::Env::DEFAULT_CONFIG_FILE )
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)
+ env.load_config(default_config_file, app) do |app, config_file, config|
+ unless config_file == default_config_file
+ env.log(:warn, "ignoring configs: #{config_file} (#{config.keys.join(',')})", Logger::WARN)
+ next
+ end
+
+ before = config.delete('before')
+ after = config.delete('after')
+
+ app.reconfigure(config)
+ end
rescue(Exception)
# catch errors and exit gracefully
# (errors usu from gem loading errors)
puts "Configuration error: #{$!.message}"
- puts "Check #{config_file} configurations"
+ puts $!.backtrace if $DEBUG
+ puts "Check #{default_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)
@@ -34,66 +65,66 @@
#
# run before script
#
begin
- eval(script.config.before.to_s)
+ eval(before.to_s)
rescue
puts "Error in before script."
- if app.options.debug
- raise
- else
- puts $!.message
- exit(1)
- end
+ handle_error($!)
+ exit(1)
end
begin
- available_commands = script.config.scripts
+ available_commands = env.commands
command = ARGV.shift
case command
when "--help", "-h", "help", "?", nil
# give some help
- puts Tap::Script.usage(__FILE__)
+ File.open(__FILE__) do |file|
+ bang_line = true
+ file.each_line do |line|
+ if bang_line
+ bang_line = false
+ next
+ end
+
+ break if line !~ /^#\s?(.*)/
+ puts $1
+ end
+ end
+
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
+ puts "version #{Tap::VERSION} -- #{Tap::WEBSITE}"
+ else
if available_commands.has_key?(command)
- # run the script, if it exists
+ # run the command, if it exists
load available_commands[command]
else
- puts "Unknown command: '#{command}'"
- puts "Type 'tap help' for usage information."
+ 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
+ handle_error($!)
+ puts "Type 'tap #{command} --help' for usage information."
end
#
# run after script
#
begin
- eval(script.config.after.to_s)
+ eval(after.to_s)
rescue
puts "Error in after script."
- if app.options.debug
- raise
- else
- puts $!.message
- exit(1)
- end
+ handle_error($!)
+ exit(1)
end