Class: Crowbar::Client::Util::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/crowbar/client/util/runner.rb

Overview

A wrapper around the Crowbar CLI for proper initialization

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Runner.



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/crowbar/client/util/runner.rb', line 30

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

Instance Attribute Details

#argvObject

Returns the value of attribute argv.



24
25
26
# File 'lib/crowbar/client/util/runner.rb', line 24

def argv
  @argv
end

#kernelObject

Returns the value of attribute kernel.



28
29
30
# File 'lib/crowbar/client/util/runner.rb', line 28

def kernel
  @kernel
end

#stderrObject

Returns the value of attribute stderr.



27
28
29
# File 'lib/crowbar/client/util/runner.rb', line 27

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



25
26
27
# File 'lib/crowbar/client/util/runner.rb', line 25

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



26
27
28
# File 'lib/crowbar/client/util/runner.rb', line 26

def stdout
  @stdout
end

Instance Method Details

#execute!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/crowbar/client/util/runner.rb', line 44

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

    App::Entry.start(argv)

    0
  rescue StandardError => e
    b = e.backtrace

    stderr.puts(
      "#{b.shift}: #{e.message} (#{e.class})"
    )

    stderr.puts(
      b.map do |s|
        "\tfrom #{s}"
      end.join("\n")
    )

    1
  rescue SystemExit => e
    e.status
  ensure
    $stderr = STDERR
    $stdin = STDIN
    $stdout = STDOUT
  end

  kernel.exit(exit_code)
end