lib/site_hook/runner.rb in site_hook-0.9.16 vs lib/site_hook/runner.rb in site_hook-0.9.19

- old
+ new

@@ -1,36 +1,48 @@ -require 'site_hook' -require 'site_hook/logger' +require "site_hook" +require "site_hook/logger" + module SiteHook class Runner def initialize(argv = ARGV, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end + def execute! - exit_code = begin - $stderr = @stderr - $stdin = @stdin - $stdout = @stdout + begin SiteHook::PreLogger.new($stdin, $stdout, $stderr) SiteHook::Config.new - SiteHook::Log.new($stdin, $stdout, $stderr) - SiteHook::CLI.start(@argv) - 0 - - rescue StandardError => e - b = e.backtrace - STDERR.puts("#{b.shift}: #{e.message} (#{e.class})") - STDERR.puts(b.map{|s| "\tfrom #{s}"}.join("\n")) - 1 - rescue SystemExit => e - STDERR.puts e.status - 1 - ensure - - $stderr = STDERR - $stdin = STDIN - $stdout = STDOUT + rescue SiteHook::NoLogsError => e + FileUtils.mkpath(e.path) + rescue SiteHook::NoConfigError => e + TTY::File.create_file(e.path, SiteHook::ConfigSections.all_samples) end + exit_code = begin + $stderr = @stderr + $stdin = @stdin + $stdout = @stdout + SiteHook::PreLogger.new($stdin, $stdout, $stderr) + SiteHook::Config.new + SiteHook::Log.new($stdin, $stdout, $stderr) + SiteHook::CLI.start(@argv) + 0 + rescue StandardError => e + b = e.backtrace + unless e.class == SiteHook::NoConfigError + STDERR.puts("#{b.shift}: #{e.message} (#{e.class})") + STDERR.puts(b.map { |s| "\tfrom #{s}" }.join("\n")) + 1 + end + 0 + rescue SystemExit => e + STDERR.puts e.backtrace + STDERR.puts e.status + 1 + ensure + $stderr = STDERR + $stdin = STDIN + $stdout = STDOUT + end @kernel.exit(exit_code) end end -end \ No newline at end of file +end