class DoSnapshot::Runner
Public Class Methods
new(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
click to toggle source
# File lib/do_snapshot/runner.rb, line 8 def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv = argv @stdin = stdin @stdout = stdout @stderr = stderr @kernel = kernel end
Public Instance Methods
execute!()
click to toggle source
# File lib/do_snapshot/runner.rb, line 16 def execute! # rubocop:disable Metrics/MethodLength exit_code = begin run_cli rescue DoSnapshot::NoTokenError, DoSnapshot::NoKeysError => _ do_nothing_on_shown_error rescue StandardError => e display_backtrace_otherwise(e) rescue SystemExit => e e.status ensure clean_before_exit end @kernel.exit(exit_code) end
Private Instance Methods
clean_before_exit()
click to toggle source
# File lib/do_snapshot/runner.rb, line 56 def clean_before_exit DoSnapshot.cleanup $stderr = STDERR $stdin = STDIN $stdout = STDOUT end
display_backtrace_otherwise(e)
click to toggle source
# File lib/do_snapshot/runner.rb, line 49 def display_backtrace_otherwise(e) b = e.backtrace @stderr.puts("#{b.shift}: #{e.message} (#{e.class})") @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n")) 1 end
do_nothing_on_shown_error()
click to toggle source
# File lib/do_snapshot/runner.rb, line 44 def do_nothing_on_shown_error clean_before_exit 1 end
run_cli()
click to toggle source
# File lib/do_snapshot/runner.rb, line 34 def run_cli $stderr = @stderr $stdin = @stdin $stdout = @stdout DoSnapshot::CLI.start(@argv) 0 end