lib/githuh/cli/launcher.rb in githuh-0.2.0 vs lib/githuh/cli/launcher.rb in githuh-0.2.1

- old
+ new

@@ -1,10 +1,11 @@ # frozen_string_literal: true require 'dry/cli' require 'forwardable' require 'tty/box' +require 'tty/screen' require 'githuh' module Githuh module CLI class Launcher @@ -32,19 +33,32 @@ Githuh.configure_kernel_behavior! end self.command = ::Dry::CLI.new(::Githuh::CLI::Commands) command.call(arguments: argv, out: stdout, err: stderr) - rescue StandardError => e - box = TTY::Box.frame('ERROR:', ' ', e.message, **BOX_OPTIONS) - stderr.print box + lines = [e.message.gsub(/\n/, ', ')] + if e.backtrace + lines << '' + lines.concat(e.backtrace) + end + box = TTY::Box.frame(*lines, + **BOX_OPTIONS.merge( + width: TTY::Screen.width, + title: { top_center: "┤ #{e.class.name} ├" }, + )) + stderr.puts + stderr.print box ensure Githuh.restore_kernel_behavior! - exit(10) unless Githuh.in_test + exit(0) unless Githuh.in_test end + + def trace? + argv.include?('-t') || argv.include?('--trace') + end end BANNER = <<~BANNER #{'Githuh CLI'.bold.yellow} #{::Githuh::VERSION.bold.green} — API client for Github.com. @@ -53,18 +67,18 @@ BANNER BOX_OPTIONS = { padding: 1, align: :left, - title: { top_center: Githuh::BANNER }, + title: { top_center: "┤ #{Githuh::BANNER} ├" }, width: 80, style: { - bg: :red, + bg: :yellow, + fg: :black, border: { - fg: :bright_yellow, - bg: :red + fg: :red, + bg: :yellow } } }.freeze - end end