#!/usr/bin/env ruby

require 'rubygems'
require 'hiera/backend/eyaml/CLI'
require 'hiera/backend/eyaml/plugins'
require 'hiera/backend/eyaml/encryptors/pkcs7'

# Register all plugins
Hiera::Backend::Eyaml::Encryptors::Pkcs7.register
Hiera::Backend::Eyaml::Plugins.find

begin
  Hiera::Backend::Eyaml::CLI.parse
rescue StandardError => e
  Hiera::Backend::Eyaml::LoggingHelper.warn e.message
  Hiera::Backend::Eyaml::LoggingHelper.debug e.backtrace.join("\n")
  exit 1
end

begin
  Hiera::Backend::Eyaml::CLI.execute
rescue StandardError => e
  Hiera::Backend::Eyaml::LoggingHelper.warn e.message
  Hiera::Backend::Eyaml::LoggingHelper.debug e.backtrace.join("\n")
  exit 1
end
