bin/tl in testlab-1.18.1 vs bin/tl in testlab-1.19.0
- old
+ new
@@ -72,15 +72,15 @@
require 'commands/network'
require 'commands/container'
# commands_from 'commands'
-desc 'Show verbose output'
+desc 'Verbose output (or set VERBOSE=1 in your environment)'
default_value false
switch [:v, :verbose]
-desc 'Quiet mode'
+desc 'Quiet output (or set QUIET=1 in your environment)'
default_value false
switch [:q, :quiet]
desc 'Path to Labfile'
arg_name 'path/to/file'
@@ -93,23 +93,31 @@
desc 'Path to Configuration directory'
arg_name 'path/to/directory'
flag [:c, :config]
desc 'Path to Log file'
-default_value STDOUT
+default_value DEFAULT_LOG_FILE
arg_name 'path/to/log_file'
flag [:log]
pre do |global,command,options,args|
@testlab_start_time = Time.now.utc
+ @verbose = ((ENV['VERBOSE'] == '1') || (global[:verbose] == true))
+ @quiet = ((ENV['QUIET'] == '1') || (global[:quiet] == true))
- (global[:verbose] == true) and (ENV['LOG_LEVEL'] = 'DEBUG')
+ (@verbose == true) and (ENV['LOG_LEVEL'] = 'DEBUG')
+ File.exists?(global[:log]) and FileUtils.move(global[:log], DEFAULT_LOG_BACKUP)
+ logger = ZTK::Logger.new(global[:log])
+ if ((@verbose == true) || (@quiet == false))
+ logger.loggers << ::Logger.new(STDOUT)
+ end
+
@ui = ZTK::UI.new(
- :logger => ZTK::Logger.new(global[:log]),
- :verbose => global[:verbose],
- :quiet => global[:quiet]
+ :logger => logger,
+ :verbose => @verbose,
+ :quiet => @quiet
)
@ui.logger.debug { "global(#{global.inspect})" }
@ui.logger.debug { "options(#{options.inspect})" }
@ui.logger.debug { "args(#{args.inspect})" }
@@ -139,10 +147,12 @@
message = format_message("TestLab v#{TestLab::VERSION} Finished (%0.4f seconds)".black.bold % testlab_run_time)
@ui.stdout.puts(message)
@ui.logger.info { message }
end
+ File.exists?(DEFAULT_DUMP_FILE) and File.delete(DEFAULT_DUMP_FILE)
+
true
end
on_error do |exception|
@ui.stderr.puts(format_message(["ERROR:".red, exception.inspect.red.bold].join(' ')))
@@ -157,15 +167,25 @@
false
else
testlab_run_time = (Time.now.utc - @testlab_start_time)
+ dump_file = File.open(DEFAULT_DUMP_FILE, 'w')
+
+ if !@testlab.nil?
+ TestLab::Utility.log_header(@testlab).each { |line| dump_file.puts(line) }
+ end
+
+ dump_file.puts(exception.inspect)
@ui.logger.fatal { exception.inspect }
+
exception.backtrace.each do |line|
- @ui.logger.logdev.write("#{line}\n")
+ dump_file.puts(line)
+ @ui.logger << "#{line}\n"
end
message = format_message("TestLab v#{TestLab::VERSION} Aborted (%0.4f seconds)".black.bold % testlab_run_time)
+ dump_file.puts(ZTK::ANSI.uncolor(message))
@ui.stderr.puts(message)
@ui.logger.info { message }
false
end