<commit_before>module Heroku::Command
	class Addons < BaseWithApp
		def index
			installed = heroku.installed_addons(app)
			if installed.empty?
				display "No addons installed"
			else
				available, pending = installed.partition { |a| a['configured'] }
				available.map { |a| a['name'] }.sort.each do |addon|
					display addon
				end
				unless pending.empty?
					display "\n--- not configured ---"
					pending.map { |a| a['name'] }.sort.each do |addon|
						display addon.ljust(24) + "http://#{heroku.host}/myapps/#{app}/addons/#{addon}"
					end
				end
			end
		end

		def info
			addons = heroku.addons
			if addons.empty?
				display "No addons available currently"
			else
				available, beta = addons.partition { |a| !a['beta'] }
				display_addons(available)
				if !beta.empty?
					display "\n--- beta ---"
					display_addons(beta)
				end
			end
		end

		def add
			addon = args.shift
			config = {}
			args.each do |arg|
				key, value = arg.strip.split('=', 2)
				if value.nil?
					addon_error("Non-config value \"#{arg}\".  Everything after the addon name should be a key=value pair.")
					exit 1
				else
					config[key] = value
				end
			end

			display "Adding #{addon} to #{app}... ", false
			display addon_run { heroku.install_addon(app, addon, config) }
		end

		def remove
			args.each do |name|
				display "Removing #{name} from #{app}... ", false
				display addon_run { heroku.uninstall_addon(app, name) }
			end
		end

		def clear
			heroku.installed_addons(app).each do |addon|
				display "Removing #{addon['description']} from #{app}... ", false
				display addon_run { heroku.uninstall_addon(app, addon['name']) }
			end
		end

		# TODO merge with Account#confirm_billing
		def confirm_billing
			display("\n")
			display("  This action will cause your account to be billed at the end of the month")
			display("  For more information, see http://docs.heroku.com/billing")
			display("  Are you sure you want to do this? (y/n) ", false)
			if ask.downcase == 'y'
				heroku.confirm_billing
				return true
			end
		end

		private
			def display_addons(addons)
				grouped = addons.inject({}) do |base, addon|
					group, short = addon['name'].split(':')
					base[group] ||= []
					base[group] << addon.merge('short' => short)
					base
				end
				grouped.keys.sort.each do |name|
					addons = grouped[name]
					row = name.dup
					if addons.any? { |a| a['short'] }
						row << ':'
						size = row.size
						stop = false
						row << addons.map { |a| a['short'] }.sort.map do |short|
							size += short.size
							if size < 31
								short
							else
								stop = true
								nil
							end
						end.compact.join(', ')
						row << '...' if stop
					end
					display row.ljust(34) + (addons.first['url'] || '')
				end
			end

			def addon_run
				yield
				'done'
			rescue RestClient::ResourceNotFound => e
				addon_error("no addon by that name")
			rescue RestClient::RequestFailed => e
				if e.http_code == 402
					confirm_billing ? retry : 'canceled'
				else
					error = Heroku::Command.extract_error(e.http_body)
					"FAILED\n" + error
				end
			end
	end
end<commit_msg>addon_error helper was removed, use error when appropriate<commit_after>module Heroku::Command
	class Addons < BaseWithApp
		def index
			installed = heroku.installed_addons(app)
			if installed.empty?
				display "No addons installed"
			else
				available, pending = installed.partition { |a| a['configured'] }
				available.map { |a| a['name'] }.sort.each do |addon|
					display addon
				end
				unless pending.empty?
					display "\n--- not configured ---"
					pending.map { |a| a['name'] }.sort.each do |addon|
						display addon.ljust(24) + "http://#{heroku.host}/myapps/#{app}/addons/#{addon}"
					end
				end
			end
		end

		def info
			addons = heroku.addons
			if addons.empty?
				display "No addons available currently"
			else
				available, beta = addons.partition { |a| !a['beta'] }
				display_addons(available)
				if !beta.empty?
					display "\n--- beta ---"
					display_addons(beta)
				end
			end
		end

		def add
			addon = args.shift
			config = {}
			args.each do |arg|
				key, value = arg.strip.split('=', 2)
				if value.nil?
					error("Non-config value \"#{arg}\".\nEverything after the addon name should be a key=value pair")
				else
					config[key] = value
				end
			end

			display "Adding #{addon} to #{app}... ", false
			display addon_run { heroku.install_addon(app, addon, config) }
		end

		def remove
			args.each do |name|
				display "Removing #{name} from #{app}... ", false
				display addon_run { heroku.uninstall_addon(app, name) }
			end
		end

		def clear
			heroku.installed_addons(app).each do |addon|
				display "Removing #{addon['description']} from #{app}... ", false
				display addon_run { heroku.uninstall_addon(app, addon['name']) }
			end
		end

		# TODO merge with Account#confirm_billing
		def confirm_billing
			display("\n")
			display("  This action will cause your account to be billed at the end of the month")
			display("  For more information, see http://docs.heroku.com/billing")
			display("  Are you sure you want to do this? (y/n) ", false)
			if ask.downcase == 'y'
				heroku.confirm_billing
				return true
			end
		end

		private
			def display_addons(addons)
				grouped = addons.inject({}) do |base, addon|
					group, short = addon['name'].split(':')
					base[group] ||= []
					base[group] << addon.merge('short' => short)
					base
				end
				grouped.keys.sort.each do |name|
					addons = grouped[name]
					row = name.dup
					if addons.any? { |a| a['short'] }
						row << ':'
						size = row.size
						stop = false
						row << addons.map { |a| a['short'] }.sort.map do |short|
							size += short.size
							if size < 31
								short
							else
								stop = true
								nil
							end
						end.compact.join(', ')
						row << '...' if stop
					end
					display row.ljust(34) + (addons.first['url'] || '')
				end
			end

			def addon_run
				yield
				'done'
			rescue RestClient::ResourceNotFound => e
				"FAILED\nno addon by that name"
			rescue RestClient::RequestFailed => e
				if e.http_code == 402
					confirm_billing ? retry : 'canceled'
				else
					error = Heroku::Command.extract_error(e.http_body)
					"FAILED\n" + error
				end
			end
	end
end
{'fraction_non_alphanumeric': 0.1317915412640583, 'fraction_numerical': 0.003326469190559164, 'mean_word_length': 2.4845474613686536, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1658394', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2115, 'n_words': 593}