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

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

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.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/crowbar/client/util/runner.rb', line 27

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.



21
22
23
# File 'lib/crowbar/client/util/runner.rb', line 21

def argv
  @argv
end

#kernelObject

Returns the value of attribute kernel.



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

def kernel
  @kernel
end

#stderrObject

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



22
23
24
# File 'lib/crowbar/client/util/runner.rb', line 22

def stdin
  @stdin
end

#stdoutObject

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#execute!Object



41
42
43
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
# File 'lib/crowbar/client/util/runner.rb', line 41

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