Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Added a --debug flag. Maybe chaning this latter to be --verbose or --…
Browse files Browse the repository at this point in the history
…trace

Change-Id: I1fd04ebd413127ab04dae35fb3ee09642477b1e2
  • Loading branch information
vito committed Dec 18, 2012
1 parent 9b804e5 commit 2c6ab79
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/vmc/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class CLI < Mothership
option :force, :desc => "Skip interaction when possible", :alias => "-f",
:type => :boolean, :default => proc { input[:script] }

option :debug, :desc => "Print full stack trace (instead of crash log)",
:type => :boolean, :default => false

option :quiet, :desc => "Simplify output format", :alias => "-q",
:type => :boolean, :default => proc { input[:script] }

Expand Down Expand Up @@ -137,6 +140,7 @@ def execute(cmd, argv, global = {})
msg << ": #{e}" unless e.to_s.empty?
msg << "\nFor more information, see #{VMC::CRASH_FILE}"
err msg
raise if debug?
end

def log_error(e)
Expand Down Expand Up @@ -173,6 +177,10 @@ def force?
input[:force]
end

def debug?
!!input[:debug]
end

def color_enabled?
input[:color]
end
Expand Down
22 changes: 21 additions & 1 deletion spec/vmc/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
let(:cmd) { Class.new(VMC::CLI).new }

describe '#execute' do
let(:inputs) { {} }

subject do
stub(cmd).input { {} }
stub(cmd).input { inputs }
cmd.execute(nil, [])
end

Expand All @@ -15,6 +17,24 @@
mock(cmd).err "GET /foo timed out"
subject
end

context "when the debug flag is on" do
let(:inputs) { {:debug => true} }

it 'reraises' do
stub(cmd).precondition { raise StandardError.new }
expect { subject }.to raise_error(StandardError)
end
end

context "when the debug flag is off" do
it 'outputs the crash log message' do
stub(cmd).precondition { raise StandardError.new }
mock(cmd).err "StandardError: StandardError\nFor more information, see /Users/pivotal/workspace/vmc/vmc/spec/tmp/.vmc/crash"

expect { subject }.not_to raise_error(StandardError)
end
end
end
end

0 comments on commit 2c6ab79

Please sign in to comment.