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.


17
18
19
# File 'lib/berkshelf/cli.rb', line 17

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


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/berkshelf/cli.rb', line 21

def execute!
  begin
    $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 Ridley::Errors::RidleyError => e
    Berkshelf.ui.error "#{e.class} #{e}"
    Berkshelf.ui.error "\t" + e.backtrace.join("\n\t") if ENV['BERKSHELF_DEBUG']
    @kernel.exit(47)
  end
end