lib/appsignal/cli/notify_of_deploy.rb in appsignal-1.4.0.beta.1 vs lib/appsignal/cli/notify_of_deploy.rb in appsignal-2.0.0.beta.1

- old
+ new

@@ -1,39 +1,54 @@ module Appsignal class CLI class NotifyOfDeploy class << self - def run(options, config) + def run(options) + config = config_for(options[:environment]) + config[:name] = options[:name] if options[:name] + validate_active_config(config) - validate_required_options(options, [:revision, :user, :environment]) + required_config = [:revision, :user] + required_config << :environment if config.env.empty? + required_config << :name if !config[:name] || config[:name].empty? + validate_required_options(options, required_config) Appsignal::Marker.new( { :revision => options[:revision], :user => options[:user] }, config ).transmit end - protected + private def validate_required_options(options, required_options) missing = required_options.select do |required_option| val = options[required_option] val.nil? || (val.respond_to?(:empty?) && val.empty?) end - if missing.any? - puts "Missing options: #{missing.join(', ')}" - exit 1 - end + return unless missing.any? + + puts "Error: Missing options: #{missing.join(', ')}" + exit 1 end def validate_active_config(config) - unless config.active? - puts 'Exiting: No config file or push api key env var found' - exit 1 - end + return if config.active? + + puts "Error: No valid config found." + exit 1 + end + + def config_for(environment) + Appsignal::Config.new( + Dir.pwd, + environment, + {}, + Logger.new(StringIO.new) + ) end end end end end