class Giblish::Application

The 'main' class of giblish

Public Instance Methods

run(args) click to toggle source

return exit status (0 for success)

# File lib/giblish/application.rb, line 15
def run(args)
  # force immediate output
  $stdout.sync = true

  # setup logging
  Giblog.setup

  # Parse cmd line
  cmdline = CmdLineParser.new args
  Giblog.logger.debug { "cmd line args: #{cmdline.args}" }

  exit_code = execute_conversion(cmdline)
  Giblog.logger.info { "Giblish is done!" } if exit_code.zero?
  exit_code
end
run_from_cmd_line() click to toggle source

does not return, exits with status code

# File lib/giblish/application.rb, line 9
def run_from_cmd_line
  status = run(ARGV)
  exit(status)
end

Private Instance Methods

converter_factory(cmdline) click to toggle source

return the converter corresponding to the given cmd line options

# File lib/giblish/application.rb, line 48
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
execute_conversion(cmdline) click to toggle source

Convert using given args return exit code (0 for success)

# File lib/giblish/application.rb, line 35
def execute_conversion(cmdline)
  conv_error = false
  begin
    conv_error = converter_factory(cmdline).convert
  rescue StandardError => e
    log_error e
    conv_error = true
  end
  conv_error ? 1 : 0
end
log_error(exc) click to toggle source
# File lib/giblish/application.rb, line 57
    def log_error(exc)
      Giblog.logger.error do
        <<~ERR_MSG
          Error: #{exc.message}
          Backtrace:
          \t#{exc.backtrace.join("\n\t")}

          cmdline.usage
        ERR_MSG
      end
    end