def self.contact(kind)
self.internal_init
if CONTACT_LOAD_SUCCESS[kind] == false
applog(nil, :error, "A required dependency for the #{kind} contact is unavailable.")
applog(nil, :error, "Run the following commands to install the dependencies:")
CONTACT_DEPS[kind].each do |d|
applog(nil, :error, " [sudo] gem install #{d}")
end
abort
end
begin
c = Contact.generate(kind)
rescue NoSuchContactError => e
abort e.message
end
yield(c) if block_given?
c.prepare
existing_contact = self.contacts[c.name]
if self.running && existing_contact
self.uncontact(existing_contact)
end
if self.contacts[c.name] || self.contact_groups[c.name]
applog(nil, :warn, "Contact name '#{c.name}' already used for a Contact or Contact Group")
return
end
unless Contact.valid?(c) && c.valid?
abort "Exiting on invalid contact"
end
self.contacts[c.name] = c
if c.group
if self.contacts[c.group]
abort "Contact Group name '#{c.group}' already used for a Contact"
end
self.contact_groups[c.group] ||= []
self.contact_groups[c.group] << c
end
end