class MotherBrain::Cli::Runner
This is the main entry point for the CLI. It exposes the method {#execute!} to start the CliGateway
.
@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.
Public Class Methods
new(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
click to toggle source
@param [Array] argv @param [IO] stdin @param [IO] stdout @param [IO] stderr @param [Kernel] kernel
# File lib/mb/cli.rb, line 19 def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end
Public Instance Methods
execute!()
click to toggle source
Start the CLI Gateway
# File lib/mb/cli.rb, line 24 def execute! MB::CliGateway.start(@argv) rescue MBError => ex ui.error ex @kernel.exit(ex.exit_code) rescue Ridley::Errors::ConnectionFailed => ex ui.error "[ERROR] Unable to connect to the configured Chef server: #{ex.message}." ui.error "[ERROR] Check your configuration and network settings and try again." @kernel.exit(MB::ChefConnectionError.exit_code) rescue Thor::Error => ex ui.error ex.message @kernel.exit(1) rescue Errno::EPIPE # This happens if a thor command is piped to something like `head`, # which closes the pipe when it's done reading. This will also # mean that if the pipe is closed, further unnecessary # computation will not occur. @kernel.exit(0) end
ui()
click to toggle source
@return [MB::Cli::Shell::Color, MB::Cli::Shell::Basic]
# File lib/mb/cli.rb, line 45 def ui @ui ||= MB::Cli::Shell.shell.new end