bin/tap in tap-0.7.9 vs bin/tap in tap-0.8.0
- old
+ new
@@ -1,63 +1,99 @@
-#require 'rdoc/usage'
-#require 'getoptlong'
+# usage: tap <command> {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'
-# add options as needed
-#opts = GetoptLong.new(
-# [ '--help', '-h', GetoptLong::NO_ARGUMENT ])
-# opts.each do |opt, arg|
-# case opt
-# when '--help' then nil
-# end
-# end
+require File.join( File.dirname(__FILE__), "../lib/tap.rb")
+require "tap/script"
-lib_dir = File.join( File.dirname(__FILE__), "../lib/")
-require lib_dir + "tap.rb"
+app = Tap::App.instance
+script = Tap::Script.instance
-# configure the app to app.yml if it exists
-if File.exists?("app.yml")
- config = ERB.new( File.read("app.yml") ).result
- config = YAML.load(config)
- Tap::App.instance.reconfigure(config) if config
+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", "?", nil
- puts "usage: tap <command> [options] [args]"
+ when "--help", "-h", "help", "?", nil
+ # give some help
+ puts Tap::Script.usage(__FILE__)
+ puts
puts "available commands:"
+
+ commands = available_commands.keys
+ commands.unshift("help")
- commands = Tap::App.instance.glob(:script).collect do |script|
- next unless File.extname(script) == ".rb"
- Tap::App.instance.relative_filepath(:script, script).chomp(".rb")
- end
- Tap::App.glob(lib_dir + "tap/script/**/*").each do |script|
- next unless File.extname(script) == ".rb"
- command = Tap::App.relative_filepath(lib_dir + "tap/script", script).chomp(".rb")
- commands << command unless commands.include?(command)
- end
-
print " "
puts commands.sort.join("\n ")
puts
-
- else
- app_script_filepath = Tap::App.instance.filepath(:script, command + ".rb")
- tap_script_filepath = lib_dir + "tap/script/#{command}.rb"
-
- if File.exists?(app_script_filepath)
- load app_script_filepath
- elsif File.exists?(tap_script_filepath)
- load tap_script_filepath
+ puts "version #{Tap::VERSION} -- #{Tap::HOMEPAGE}"
+ else
+ if available_commands.has_key?(command)
+ # run the script, if it exists
+ load available_commands[command]
else
- raise "Unknown command: '#{command}'"
+ puts "Unknown command: '#{command}'"
+ puts "Type 'tap help' for usage information."
end
end
rescue
- if Tap::App.instance.options.debug
+ if app.options.debug
raise
else
puts $!.message
- puts "Type 'tap help' for usage information."
+ 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