bin/tap in tap-0.9.1 vs bin/tap in tap-0.10.0
- old
+ new
@@ -6,122 +6,109 @@
# 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")
+tap_root_dir = File.dirname(__FILE__) + "/.."
+require "#{tap_root_dir}/lib/tap.rb"
# setup the environment
-env = Tap::Env.instance
-app = Tap::App.instance
+begin
+
+ $DEBUG = true if ARGV.delete('-d-')
+ before = nil
+ after = nil
+ aliases = nil
-env.logger = app.logger
-env.debug_setup if ARGV.delete('-d-')
+ app = Tap::App.instance
+ env = Tap::Env.instantiate(app, Tap::Env.load_config(Tap::Env::GLOBAL_CONFIG_FILE), app.logger) do |unhandled_configs|
+ before = unhandled_configs.delete(:before)
+ after = unhandled_configs.delete(:after)
+
+ aliases = unhandled_configs.delete(:alias)
+ Tap::Support::Validation.validate(aliases, [Hash]) if aliases
-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
+ unless unhandled_configs.empty?
+ local.log(:warn, "ignoring non-env configs: #{unhandled_configs.keys.join(',')}", Logger::DEBUG)
+ end
end
-end
-
-# configure the app to tap.yml if it exists
-default_config_file = Tap::Env::DEFAULT_CONFIG_FILE
-begin
- env.load_config(default_config_file, app) do |non_env_configs|
- before = non_env_configs.delete('before')
- after = non_env_configs.delete('after')
-
- app.reconfigure(non_env_configs)
+ # add all gems if no gems are specified (Note this is VERY SLOW ~ 1/3 the overhead for tap)
+ if !File.exists?(Tap::Env::DEFAULT_CONFIG_FILE)
+ env.gems = Tap::Env.known_gems(true)
end
- env.discover_gems unless File.exists?(default_config_file)
+ tap = Tap::Env.instance_for(tap_root_dir)
+ env.push(tap)
-rescue(Exception)
+rescue(Tap::Env::ConfigError)
# catch errors and exit gracefully
# (errors usu from gem loading errors)
- puts "Configuration error: #{$!.message}"
- puts $!.backtrace if $DEBUG
- puts "Check #{default_config_file} configurations"
+ puts $!.message
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}"
+#
+# setup after script
+#
+
+at_exit do
+ begin
+ eval(after) if after != nil
+ rescue(Exception)
+ puts "Error in after script."
+ env.handle_error($!)
+ exit(1)
+ end
end
#
# run before script
#
+
begin
- eval(before.to_s)
-rescue
+ eval(before) if before != nil
+rescue(Exception)
puts "Error in before script."
- handle_error($!)
+ env.handle_error($!)
exit(1)
-end
+end
+#
+# run tap
+#
+
begin
- available_commands = env.commands
+ env.activate
+
command = ARGV.shift
+ if aliases && aliases.has_key?(command)
+ aliases[command].reverse_each {|arg| ARGV.unshift(arg)}
+ command = ARGV.shift
+ end
case command
- when "--help", "-h", "help", "?", nil
+ when nil, '--help'
# give some help
- 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
+ require 'tap/support/command_line'
+ puts Tap::Support::CommandLine.usage(__FILE__)
puts
puts "available commands:"
-
- commands = available_commands.keys
- commands.unshift("help")
-
- print " "
- puts commands.sort.join("\n ")
+ puts env.summarize(:commands)
puts
- puts "version #{Tap::VERSION} -- #{Tap::WEBSITE}"
+ puts "version #{Tap::VERSION} -- #{Tap::WEBSITE}"
else
- if available_commands.has_key?(command)
- # run the command, if it exists
- load available_commands[command]
+ if path = env.search(:commands, command)
+ load path # run the command, if it exists
else
puts "Unknown command: '#{command}'"
puts "Type 'tap help' for usage information."
end
end
rescue
- handle_error($!)
- puts "Type 'tap #{command} --help' for usage information."
+ env.handle_error($!)
end
-#
-# run after script
-#
-begin
- eval(after.to_s)
-rescue
- puts "Error in after script."
- handle_error($!)
- exit(1)
-end
+exit(0)
\ No newline at end of file