#!/usr/bin/env ruby
# -*- encoding: utf-8 -*-
$:.push File.expand_path(File.join('..','..','lib'), __FILE__)

require "rubygems"
require "bundler"
Bundler.setup
require 'post_office_manager'
require 'dotenv'

ENV['RAILS_ENV'] ||= 'development'
Dotenv.overload(".env.#{ENV['RAILS_ENV']}")
Dotenv.overload(".env.#{ENV['RAILS_ENV']}.local")

FileUtils.mkdir_p('tmp/pids') unless File.exists?('tmp/pids')

if ARGV.include?('start')
  puts "Starting Post Office!"
  PostOfficeManager.start_post_office
elsif ARGV.include?('stop')
  puts "Stopping Post Office!"
  PostOfficeManager.stop_post_office
elsif ARGV.include?('run')
  PostOfficeManager.run_post_office
end