class Honeybadger::CLI::Main
Public Class Methods
Source
# File lib/honeybadger/cli/main.rb, line 26 def self.project_options option :api_key, required: false, aliases: :'-k', type: :string, desc: 'Api key of your Honeybadger application' option :environment, required: false, aliases: [:'-e', :'-env'], type: :string, desc: 'Environment this command is being executed in (i.e. "production", "staging")' option :skip_rails_load, required: false, type: :boolean, desc: 'Flag to skip rails initialization' end
Public Instance Methods
Source
# File lib/honeybadger/cli/main.rb, line 76 def deploy config = build_config(options) if config.get(:api_key).to_s =~ BLANK say("No value provided for required options '--api-key'") exit(1) end Deploy.new(options, [], config).run rescue => e log_error(e) exit(1) end
Source
# File lib/honeybadger/cli/main.rb, line 116 def exec(*args) if args.size == 0 say("honeybadger: exec needs a command to run", :red) exit(1) end config = build_config(options) if config.get(:api_key).to_s =~ BLANK say("No value provided for required options '--api-key'", :red) exit(1) end Exec.new(options, args, config).run rescue => e log_error(e) exit(1) end
Source
# File lib/honeybadger/cli/main.rb, line 32 def help(*args, &block) if args.size == 0 say(<<-WELCOME) ⚡ Honeybadger v#{VERSION} Honeybadger is your favorite error tracker for Ruby. When your app raises an exception we notify you with all the context you need to fix it. The Honeybadger CLI provides tools for interacting with Honeybadger via the command line. If you need support, please drop us a line: support@honeybadger.io WELCOME end super end
Calls superclass method
Source
# File lib/honeybadger/cli/main.rb, line 54 def install(api_key) Install.new(options, api_key).run rescue => e log_error(e) exit(1) end
Source
# File lib/honeybadger/cli/main.rb, line 99 def notify config = build_config(options) if config.get(:api_key).to_s =~ BLANK say("No value provided for required options '--api-key'") exit(1) end Notify.new(options, [], config).run rescue => e log_error(e) exit(1) end
Source
# File lib/honeybadger/cli/main.rb, line 64 def test Test.new(options).run rescue => e log_error(e) exit(1) end
Private Instance Methods
Source
# File lib/honeybadger/cli/main.rb, line 144 def build_config(options) load_env(options) config = Honeybadger.config config.set(:report_data, true) config.set(:api_key, fetch_value(options, 'api_key')) if options.has_key?('api_key') config.set(:env, fetch_value(options, 'environment')) if options.has_key?('environment') config end
Source
# File lib/honeybadger/cli/main.rb, line 140 def fetch_value(options, key) options[key] == key ? nil : options[key] end
Source
# File lib/honeybadger/cli/main.rb, line 155 def load_env(options) # Initialize Rails when running from Rails root. environment_rb = File.join(Dir.pwd, 'config', 'environment.rb') if File.exist?(environment_rb) load_rails_env_if_allowed(environment_rb, options) end # Ensure config is loaded (will be skipped if initialized by Rails). Honeybadger.config.load! end
Source
# File lib/honeybadger/cli/main.rb, line 174 def load_rails_env(environment_rb) begin require 'rails' rescue LoadError # No Rails, so skip loading Rails environment. return end require environment_rb end
Source
# File lib/honeybadger/cli/main.rb, line 165 def load_rails_env_if_allowed(environment_rb, options) # Skip Rails initialization according to option flag if options.has_key?('skip_rails_load') && fetch_value(options, 'skip_rails_load') say("Skipping Rails initialization.") else load_rails_env(environment_rb) end end
Source
# File lib/honeybadger/cli/main.rb, line 184 def log_error(e) case e when *Util::HTTP::ERRORS say(<<-MSG, :red) !! --- Failed to notify Honeybadger ------------------------------------------- !! # What happened? We encountered an HTTP error while contacting our service. Issues like this are usually temporary. # Error details #{e.class}: #{e.message}\n at #{e.backtrace && e.backtrace.first} # What can I do? - Retry the command. - Make sure you can connect to api.honeybadger.io (`curl https://api.honeybadger.io/v1/notices`). - If you continue to see this message, email us at support@honeybadger.io (don't forget to attach this output!) !! --- End -------------------------------------------------------------------- !! MSG else say(<<-MSG, :red) !! --- Honeybadger command failed --------------------------------------------- !! # What did you try to do? You tried to execute the following command: `honeybadger #{ARGV.join(' ')}` # What actually happend? We encountered a Ruby exception and were forced to cancel your request. # Error details #{e.class}: #{e.message} #{e.backtrace && e.backtrace.join("\n ")} # What can I do? - If you're calling the `install` or `test` command in a Rails app, make sure you can boot the Rails console: `bundle exec rails console`. - Retry the command. - If you continue to see this message, email us at support@honeybadger.io (don't forget to attach this output!) !! --- End -------------------------------------------------------------------- !! MSG end end