aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/exceptions.rb28
-rw-r--r--Library/brew.rb8
2 files changed, 27 insertions, 9 deletions
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 130d3f505..144f70768 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -1,6 +1,28 @@
-class UsageError < RuntimeError; end
-class FormulaUnspecifiedError < UsageError; end
-class KegUnspecifiedError < UsageError; end
+class UsageError < RuntimeError
+ attr_reader :reason
+
+ def initialize(reason = nil)
+ @reason = reason
+ end
+
+ def to_s
+ s = "Invalid usage"
+ s += ": #{reason}" if reason
+ s
+ end
+end
+
+class FormulaUnspecifiedError < UsageError
+ def initialize
+ super "This command requires a formula argument"
+ end
+end
+
+class KegUnspecifiedError < UsageError
+ def initialize
+ super "This command requires a keg argument"
+ end
+end
class MultipleVersionsInstalledError < RuntimeError
attr_reader :name
diff --git a/Library/brew.rb b/Library/brew.rb
index 222b432ac..ebb144792 100644
--- a/Library/brew.rb
+++ b/Library/brew.rb
@@ -113,13 +113,9 @@ begin
end
end
-rescue FormulaUnspecifiedError
- abort "This command requires a formula argument"
-rescue KegUnspecifiedError
- abort "This command requires a keg argument"
-rescue UsageError
+rescue UsageError => e
require "cmd/help"
- Homebrew.help cmd, :usage_error => "Invalid usage"
+ Homebrew.help cmd, :usage_error => e.message
rescue SystemExit => e
onoe "Kernel.exit" if ARGV.verbose? && !e.success?
$stderr.puts e.backtrace if ARGV.debug?