Permalink
Browse files

rename Berkshelf::Main to Berkshelf::Cli::Runner

  • Loading branch information...
1 parent e11cbdb commit 7bec0ee302f608d249f88710bebeb2cd75f3bd04 @reset reset committed Jun 23, 2013
Showing with 37 additions and 34 deletions.
  1. +2 −2 bin/berks
  2. +4 −4 features/support/env.rb
  3. +31 −0 lib/berkshelf/cli.rb
  4. +0 −28 lib/berkshelf/main.rb
View
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
$:.push File.expand_path('../../lib', __FILE__)
-require 'berkshelf/main'
+require 'berkshelf/cli'
-Berkshelf::Main.new(ARGV.dup).execute!
+Berkshelf::Cli::Runner.new(ARGV.dup).execute!
View
@@ -6,7 +6,7 @@
require 'aruba/spawn_process'
require 'cucumber/rspec/doubles'
- require 'berkshelf/main'
+ require 'berkshelf/cli'
Dir['spec/support/**/*.rb'].each { |f| require File.expand_path(f) }
@@ -17,8 +17,8 @@
at_exit { Berkshelf::RSpec::ChefServer.stop }
Before do
- Aruba::InProcess.main_class = Berkshelf::Main
- Aruba.process = Aruba::InProcess
+ Aruba::InProcess.main_class = Berkshelf::Cli::Runner
+ Aruba.process = Aruba::InProcess
stub_kitchen!
purge_store_and_configs!
@@ -48,5 +48,5 @@
end
Spork.each_run do
- require 'berkshelf/main'
+ require 'berkshelf/cli'
end
View
@@ -7,6 +7,37 @@
module Berkshelf
class Cli < Thor
+ # This is the main entry point for the CLI. It exposes the method {#execute!} to
+ # start the CLI.
+ #
+ # @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.
+ class Runner
+ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
+ @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
+ end
+
+ 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
+ end
+
class << self
def dispatch(meth, given_args, given_opts, config)
unless (given_args & ['-h', '--help']).empty?
View
@@ -1,28 +0,0 @@
-require_relative 'cli'
-
-module Berkshelf
- class Main
- def initialize(argv, stdin=STDIN, stdout=STDOUT, stderr=STDERR, kernel=Kernel)
- @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
- end
-
- 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
- end
-end

0 comments on commit 7bec0ee

Please sign in to comment.