# -*- encoding: UTF-8 -*-
# enfeditor version: 0.1.1.1
require 'enfeditor'
require 'logger'
include EnfEditor


class ApplyCustomizeSetting

  def initialize
    @logger = Logger.new( STDOUT )
  end

  def exec_with_log( message, &block )
    @logger.info "#{message} Start..."
    yield
    @logger.info "#{message} done"
  end

  def execute( argv )
    EnfEditor::EESession.open( argv ) do |session|
      input = session.parameter['inputfile']
      outputfile = session.parameter['outputfile']

      exec_with_log( "Reading enf:" + input.to_s ) do
        session.read_enf( input )
      end

      # TODO: Implement special data handling here

      exec_with_log( "Writing enf:" + outputfile.to_s ) do
        session.write_enf( outputfile )
      end
    end
  rescue Exception => ex
    @logger.error "Failed."
    @logger.error ex
    raise ex
  else
    @logger.info "Complete."
  end
end

if $0 == __FILE__
  # main program
  exec = ApplyCustomizeSetting.new
  exec.execute( ARGV )
end