Sha256: 85cdb3fbbc9bc2547713f14f737313230e7a01f32986ca0343d0220e6412956d

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

module MailRoom
  class CLI
    attr_accessor :configuration, :coordinator

    def initialize(args)
      options = {}

      OptionParser.new do |parser|
        parser.banner = [
          "Usage: #{@name} [-c config_file]\n",
          "       #{@name} --help\n"
        ].compact.join

        parser.on('-c', '--config FILE') do |path|
          options[:config_path] = path
        end

        # parser.on("-l", "--log FILE") do |path|
        #   options[:log_path] = path
        # end

        parser.on_tail("-?", "--help", "Display this usage information.") do
          puts "#{parser}\n"
          exit
        end
      end.parse!(args)

      self.configuration = Configuration.new(options)
      self.coordinator = Coordinator.new(configuration.mailboxes)
    end

    def start
      Signal.trap(:INT) do
        stop
      end

      Signal.trap(:TERM) do
        exit
      end

      coordinator.run
    end

    def stop
      coordinator.quit
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mail_room-0.1.0 lib/mail_room/cli.rb
mail_room-0.0.3 lib/mail_room/cli.rb
mail_room-0.0.2 lib/mail_room/cli.rb