Skip to content

Commit

Permalink
Merge pull request #55 from jamesiarmes/doctor-exit
Browse files Browse the repository at this point in the history
Ensure that doctor exits non-zero if any checks fail.
  • Loading branch information
glennpratt committed Mar 10, 2016
2 parents 942c2ad + 57d83e0 commit bca2a47
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/moonshot/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def delete

desc :doctor, 'Run configuration checks against current environment.'
def doctor
controller.doctor
success = controller.doctor
raise Thor::Error, 'One or more checks failed.' unless success
end
end
end
20 changes: 14 additions & 6 deletions lib/moonshot/controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ def delete

def doctor
# @todo use #run_hook when Stack becomes an InfrastructureProvider
stack.doctor_hook
run_hook(:build, :doctor)
run_hook(:repo, :doctor)
run_hook(:deploy, :doctor)
run_plugins(:doctor)
success = true
success &&= stack.doctor_hook
success &&= run_hook(:build, :doctor)
success &&= run_hook(:repo, :doctor)
success &&= run_hook(:deploy, :doctor)
results = run_plugins(:doctor)

success = false if results.value?(false)
success
end

def stack
Expand Down Expand Up @@ -125,9 +129,13 @@ def run_hook(type, name, *args)
end

def run_plugins(type)
results = {}
@config.plugins.each do |plugin|
plugin.send(type, resources) if plugin.respond_to?(type)
next unless plugin.respond_to?(type)
results[plugin] = plugin.send(type, resources)
end

results
end

def get_mechanism(type)
Expand Down
5 changes: 5 additions & 0 deletions lib/moonshot/doctor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ def doctor_hook
private

def run_all_checks
success = true
puts
puts self.class.name.split('::').last
private_methods.each do |meth|
begin
send(meth) if meth =~ /^doctor_check_/
rescue DoctorCritical
# Stop running checks in this Mechanism.
success = false
break
rescue => e
success = false
print ' ✗ '.red
puts "Exception while running check: #{e.class}: #{e.message.lines.first}"
break
end
end

success
end

def success(str)
Expand Down

0 comments on commit bca2a47

Please sign in to comment.