Class: OneviewSDK::Cli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/oneview-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.


23
24
25
26
27
28
29
# File 'lib/oneview-sdk/cli.rb', line 23

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


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

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

    OneviewSDK::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