Class: Berkshelf::Cli::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/cli.rb

Overview

Note:

the arity of #initialize and #execute! are extremely important 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.

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Runner.



14
15
16
# File 'lib/berkshelf/cli.rb', line 14

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/berkshelf/cli.rb', line 18

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

  Berkshelf::Cli.start(@argv)
  @kernel.exit(0)
rescue Berkshelf::BerkshelfError => e
  Berkshelf.ui.error e
  Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV["BERKSHELF_DEBUG"]
  @kernel.exit(e.status_code)
rescue => e
  Berkshelf.ui.error "#{e.class} #{e}"
  Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV["BERKSHELF_DEBUG"]
  @kernel.exit(47)
end