Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Exit with bad exit code on command failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMcQuaid committed Mar 29, 2012
1 parent c6d37fb commit 48a82e5
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/audit.rb
Expand Up @@ -420,7 +420,7 @@ def audit

if errors
puts "#{problem_count} problems in #{brew_count} brews"
exit 1
Homebrew.failed = true
end
end
end
12 changes: 10 additions & 2 deletions Library/Homebrew/cmd/bottle.rb
Expand Up @@ -4,8 +4,16 @@

module Homebrew extend self
def bottle_formula f
return onoe "Formula not installed: #{f.name}" unless f.installed?
return onoe "Formula not installed with '--build-bottle': #{f.name}" unless built_bottle? f
unless f.installed?
onoe "Formula not installed: #{f.name}"
Homebrew.failed = true
return
end

unless built_bottle? f
onoe "Formula not installed with '--build-bottle': #{f.name}"
Homebrew.failed = true
end

directory = Pathname.pwd
filename = bottle_filename f
Expand Down
9 changes: 3 additions & 6 deletions Library/Homebrew/cmd/doctor.rb
Expand Up @@ -879,22 +879,19 @@ def check_os_version

module Homebrew extend self
def doctor
raring_to_brew = true

checks = Checks.new

checks.methods.select{ |method| method =~ /^check_/ }.sort.each do |method|
out = checks.send(method)
unless out.nil? or out.empty?
puts unless raring_to_brew
puts unless Homebrew.failed?
lines = out.to_s.split('\n')
opoo lines.shift
puts lines
raring_to_brew = false
Homebrew.failed = true
end
end

puts "Your system is raring to brew." if raring_to_brew
exit raring_to_brew ? 0 : 1
puts "Your system is raring to brew." unless Homebrew.failed?
end
end
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/install.rb
Expand Up @@ -77,6 +77,7 @@ def install_formulae formulae
fi.finish
rescue CannotInstallFormulaError => e
onoe e.message
Homebrew.failed = true
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/cmd/test.rb
Expand Up @@ -13,21 +13,24 @@ def test
# Cannot test uninstalled formulae
unless f.installed?
puts "#{f.name} not installed"
Homebrew.failed = true
next
end

# Cannot test formulae without a test method
unless f.respond_to? :test
puts "#{f.name} defines no test"
Homebrew.failed = true
next
end

puts "Testing #{f.name}"
begin
# tests can also return false to indicate failure
puts "#{f.name}: failed" if f.test == false
raise if f.test == false
rescue
puts "#{f.name}: failed"
Homebrew.failed = true
end
end
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cmd/uninstall.rb
Expand Up @@ -35,5 +35,6 @@ def uninstall
rescue MultipleVersionsInstalledError => e
onoe e
puts "Use `brew remove --force #{e.name}` to remove all versions."
Homebrew.failed = true
end
end
2 changes: 2 additions & 0 deletions Library/Homebrew/cmd/upgrade.rb
Expand Up @@ -67,9 +67,11 @@ def upgrade_formula f
installer.finish
rescue CannotInstallFormulaError => e
onoe e
Homebrew.failed = true
rescue BuildError => e
e.dump
puts
Homebrew.failed = true
ensure
# restore previous installation state if build failed
outdated_keg.link if outdated_keg and not f.installed? rescue nil
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/global.rb
Expand Up @@ -79,6 +79,9 @@ def mkpath
require 'fileutils'
module Homebrew extend self
include FileUtils

attr_accessor :failed
alias_method :failed?, :failed

This comment has been minimized.

Copy link
@adamv

adamv Mar 29, 2012

Contributor

Is this typical Ruby style?

This comment has been minimized.

Copy link
@mistydemeo

mistydemeo Mar 29, 2012

Member

Yes, if a method is a status query it's typical to include a question mark in the method name.

Since instance variables can't have question marks in their names, it's necessary to make some other way to access them. Though I'd typically write my own accessor (def failed?; @failed; end) rather than alias so there's only one method name.

This comment has been minimized.

Copy link
@MikeMcQuaid

MikeMcQuaid Mar 29, 2012

Author Member

Yeh, I considered that way @mistydemeo but this was less code so just did it :)

end

FORMULA_META_FILES = %w[README README.md ChangeLog CHANGES COPYING LICENSE LICENCE COPYRIGHT AUTHORS]
Expand Down
2 changes: 2 additions & 0 deletions bin/brew
Expand Up @@ -112,4 +112,6 @@ rescue Exception => e
puts " #{Tty.em}#{ISSUES_URL}#{Tty.reset}"
puts e.backtrace
exit 1
else
exit 1 if Homebrew.failed?
end

0 comments on commit 48a82e5

Please sign in to comment.