Class: Tlog::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/tlog/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ Application

Returns a new instance of Application.



4
5
6
7
# File 'lib/tlog/application.rb', line 4

def initialize(input, output)
  @input = input
  @output = output
end

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tlog/application.rb', line 9

def run
  command_name = ""
  outcome = false
  begin
    command_name = @input.args.shift
    command = find(command_name)
    prepare_command(command)
    outcome = run_command(command)
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
    @output.error($!)
    @output.error(@optparse.to_s)
  rescue Tlog::Error::CommandInvalid
    @output.error(command_name + " command invalid: " + $!.message)
    @output.error(@optparse.to_s)
  rescue Tlog::Error::CommandNotFound, OptionParser::MissingArgument
    @output.error($!)
    @output.error(@optparse.to_s)
  rescue
    @output.error($!)
  end
  return outcome
end