require 'commander' require_relative './version' module Erorr class ErorrTestException < StandardError; end class CLI include Commander::Methods def run program :name, 'erorr' program :version, Erorr::VERSION program :description, 'Ruby/Rails client for erorr.app' never_trace! command 'setup' do |c| c.syntax = 'erorr setup API-KEY' c.description = 'Creates erorr.app\'s configuration file config/erorr.yml and populates it with the provided API-KEY.' c.action do |args, _options| api_key = args[0] if File.exist? config_file_path say_error 'Erorr config file already exists.' exit(0) end unless api_key say_error 'Please provide an API KEY.' exit(0) end configuration_file = <<~YAML --- api_key: #{api_key} YAML File.open(config_file_path, 'w') { |file| file.write(configuration_file) } say_success <<~MSG erorr.app client configured successfully! Test the integration by sending a test notification: bundle exec erorr test-notify If all is well, you'll see the test notification in https://erorr.app. MSG end end command 'test-notify' do |c| c.syntax = 'erorr test-notify' c.description = 'Send a test notification to erorr.app' c.action do |args, _options| require File.expand_path('config/environment') Erorr.configure do |config| config.enabled_for << 'development' end begin raise ErorrTestException.new('Test message') rescue ErorrTestException => e if Erorr.notify e, location: 'erorr test-notify' say_success 'Test notification sent successfully.' else say_error 'Test notification could not be delivered.' end Erorr::Transport::HTTPAsync.shut_down end end end run! end def config_file_path File.expand_path 'config/erorr.yml' end def say_success(message) say color(message, :green) end def say_error(message) say color(message, :red) end end end