Class: Jinx::CLI::Application

Inherits:
Logger::Application
  • Object
show all
Defined in:
lib/jinx/cli/application.rb

Overview

Extends the standard Logger::Application to use the Log and add start functionality.

Direct Known Subclasses

Command

Instance Method Summary collapse

Constructor Details

#initialize(appname = nil) ⇒ Application

Returns a new instance of Application.

Parameters:

  • appname (String) (defaults to: nil)

    the application name



9
10
11
12
13
14
15
# File 'lib/jinx/cli/application.rb', line 9

def initialize(appname=nil)
  super(appname)
  # set the application logger
  @log = logger
  @log.progname = @appname
  @level = @log.level
end

Instance Method Details

#start(*args, &block) ⇒ Object

Overrides Logger::Application start with the following enhancements:

  • pass arguments and a block to the application run method

  • improve the output messages

  • print an exception to stderr as well as the log



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jinx/cli/application.rb', line 21

def start(*args, &block)
  rc = 1
  begin
    rc = run(*args, &block)
  rescue
    log(FATAL, "#{@appname} detected an exception: #{$!}\n#{$@.qp}")
    msg = "#{@appname} was unsuccessful: #{$!}."
    msg += "\nSee the log #{Log.instance.file} for more information." if Log.instance.file
    $stderr.puts msg
  ensure
    log(INFO, "#{@appname} completed with status #{rc}.")
  end
end