lib/giblish/application.rb in giblish-0.7.6 vs lib/giblish/application.rb in giblish-0.8.0

- old
+ new

@@ -1,21 +1,15 @@ - require_relative "cmdline" require_relative "core" require_relative "utils" module Giblish + # The 'main' class of giblish class Application - - # return exit status (0 for success) - def run_with_args(args) - run args - end - # does not return, exits with status code def run_from_cmd_line - status = run ARGV + status = run(ARGV) exit(status) end # return exit status (0 for success) def run(args) @@ -25,39 +19,48 @@ # setup logging Giblog.setup # Parse cmd line cmdline = CmdLineParser.new args - Giblog.logger.debug { "cmd line args: #{cmdline.args}" } - # Convert using given args + exit_code = execute_conversion(cmdline) + Giblog.logger.info { "Giblish is done!" } if exit_code.zero? + exit_code + end + + private + + # Convert using given args + # return exit code (0 for success) + def execute_conversion(cmdline) conv_error = false begin - if cmdline.args[:gitRepoRoot] - Giblog.logger.info { "User asked to parse a git repo" } - gc = GitRepoConverter.new cmdline.args - conv_error = gc.convert - else - tc = FileTreeConverter.new cmdline.args - conv_error = tc.convert - end - Giblog.logger.info { "Giblish is done!" } - rescue Exception => e + conv_error = converter_factory(cmdline).convert + rescue StandardError => e log_error e conv_error = true end conv_error ? 1 : 0 end - private + # return the converter corresponding to the given cmd line + # options + def converter_factory(cmdline) + if cmdline.args[:gitRepoRoot] + Giblog.logger.info { "User asked to parse a git repo" } + GitRepoConverter.new(cmdline.args) + else + FileTreeConverter.new(cmdline.args) + end + end - def log_error(ex) + def log_error(exc) Giblog.logger.error do <<~ERR_MSG - Error: #{ex.message} + Error: #{exc.message} Backtrace: - \t#{ex.backtrace.join("\n\t")} + \t#{exc.backtrace.join("\n\t")} cmdline.usage ERR_MSG end end