Class: ILO_SDK::Cli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/ilo-sdk/cli.rb

Overview

Runner class to enable testing

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Runner.


21
22
23
24
25
26
27
# File 'lib/ilo-sdk/cli.rb', line 21

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

Instance Method Details

#execute!Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ilo-sdk/cli.rb', line 29

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

    ILO_SDK::Cli.start(@argv)
    0
  rescue StandardError => e
    b = e.backtrace
    @stderr.puts("#{b.shift}: #{e.message} (#{e.class})")
    @stderr.puts(b.map { |s| "\tfrom #{s}" }.join("\n"))
    1
  rescue SystemExit => e
    e.status
  end

  # Proxy our exit code back to the injected kernel.
  @kernel.exit(exit_code)
end