Permalink
Browse files

add a simple executable

  • Loading branch information...
1 parent cc6ee38 commit f72d69dd37ceeaeadbc0465e98fe0d866c35bab7 @shime shime committed Oct 4, 2012
Showing with 47 additions and 0 deletions.
  1. +1 −0 airbrake.gemspec
  2. +46 −0 bin/airbrake
View
@@ -8,6 +8,7 @@ Gem::Specification.new do |s|
s.summary = %q{Send your application errors to our hosted service and reclaim your inbox.}
s.require_paths = ["lib"]
+ s.executables << "airbrake"
s.files = Dir["{generators/**/*,lib/**/*,rails/**/*,resources/*,script/*}"] +
%w(airbrake.gemspec CHANGELOG Gemfile Guardfile INSTALL MIT-LICENSE Rakefile README_FOR_HEROKU_ADDON.md README.md TESTING.md SUPPORTED_RAILS_VERSIONS install.rb)
s.test_files = Dir.glob("{test,spec,features}/**/*")
View
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+require "airbrake"
+
+def parse_options(array = [])
+ opts = Hash[*array]
+ opts[:error] = opts.delete("-e") || opts.delete("--error") { RuntimeError }
+ opts[:message] = opts.delete("-m") || opts.delete("--message") { "I've made a huge mistake" }
+ opts[:api_key] = opts.delete("-k") || opts.delete("--api-key")
+ opts[:host] = opts.delete("-h") || opts.delete("--host")
+ opts[:port] = opts.delete("-p") || opts.delete("--port")
+ opts
+end
+
+args = ARGV.dup
+command = args.shift.strip rescue nil
+
+case command
+ when 'raise'
+ options = parse_options(ARGV[1..-1])
+ abort "You didn't provide API_KEY so nothing was raised."\
+ " Refer to usage for more info (airbrake --help)." unless options[:api_key]
+ Airbrake.configure do |c|
+ c.api_key = options[:api_key]
+ c.host = options[:host] if options[:host]
+ c.port = options[:port] if options[:port]
+ end
+ exception_id = Airbrake.notify(:error_class => options[:error],
+ :error_message => "#{options[:error]}: #{options[:message]}",
+ :cgi_data => ENV)
+ abort "Error sending exception to Airbrake server. Try again later." unless exception_id
+ puts "Exception sent successfully: http://airbrake.io/locate/#{exception_id}"
+ else
+ puts <<USAGE
+Usage: airbrake [COMMAND] [OPTION]...
+Commands:
+ raise # Raise an exception specified by ERROR and MESSAGE.
+
+Options:
+ -e, [--error=ERROR] # Error class to raise. Default: RuntimeError
+ -m, [--message=MESSAGE] # Error message. Default: "I've made a huge mistake"
+ -k, [--api-key=API_KEY] # Api key of your Airbrake application.
+ -h, [--host=HOST] # URL of the Airbrake API server. Default: api.airbrake.io
+ -p, [--port=PORT] # Port of the Airbrake API server. Default: 80
+ -h, [--help] # Show this usage
+USAGE
+ end

0 comments on commit f72d69d

Please sign in to comment.