Class: Arli::CLI::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/arli/cli/runner.rb

Overview

For the reasons this file is the way it is, please refer to github.com/erikhuda/thor/wiki/Integrating-with-Aruba-In-Process-Runs

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ Runner

Returns a new instance of Runner.



9
10
11
# File 'lib/arli/cli/runner.rb', line 9

def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
  @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
end

Instance Method Details

#execute!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arli/cli/runner.rb', line 13

def execute!
  exit_code = begin
    $stderr = @stderr
    $stdin  = @stdin
    $stdout = @stdout

    Arli::CLI::App.new(@argv).start
    print_debug_info
    0
  rescue StandardError
    1
  rescue SystemExit => e
    e.status
  ensure
    $stderr = STDERR
    $stdin  = STDIN
    $stdout = STDOUT
  end
  @kernel.exit(exit_code)
end


34
35
36
37
# File 'lib/arli/cli/runner.rb', line 34

def print_debug_info
  $stdout.puts JSON.pretty_generate(Arli.config.to_hash).gsub(/("\w+":)/, '\1'.bold.blue) \
    if Arli.config.debug
end