Class: Omnibus::CLI::Runner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/omnibus/cli.rb

Overview

Note:

the arity of #initialize and #execute! are extremely important

This is the main entry point for the CLI. It exposes the method #execute! to start the CLI.

for testing purposes. It is a requirement to perform in-process testing with Aruba. In process testing is much faster than spawning a new Ruby process for each test.

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

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


32
33
34
# File 'lib/omnibus/cli.rb', line 32

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


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/omnibus/cli.rb', line 36

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

  Omnibus::CLI.start(@argv)
  @kernel.exit(0)
rescue Omnibus::Error => e
  error = Omnibus.ui.set_color(e.message, :red)
  backtrace = Omnibus.ui.set_color("\n" + e.backtrace.join("\n  "), :red)
  Omnibus.ui.error(error)
  Omnibus.ui.error(backtrace)

  if e.respond_to?(:status_code)
    @kernel.exit(e.status_code)
  else
    @kernel.exit(1)
  end
end