Class: MailRoom::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_room/cli.rb

Overview

The CLI parses ARGV into configuration to start the coordinator with.

Author:

  • Tony Pitale

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Initialize a new CLI instance to handle option parsing from arguments

into configuration to start the coordinator running on all mailboxes

Parameters:

  • args (Array)

    ‘ARGV` passed from `bin/mail_room`



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mail_room/cli.rb', line 11

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('-q', '--quiet') do
      options[:quiet] = true
    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

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



5
6
7
# File 'lib/mail_room/cli.rb', line 5

def configuration
  @configuration
end

#coordinatorObject

Returns the value of attribute coordinator.



5
6
7
# File 'lib/mail_room/cli.rb', line 5

def coordinator
  @coordinator
end

Instance Method Details

#startObject

Start the coordinator running, sets up signal traps



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mail_room/cli.rb', line 43

def start
  Signal.trap(:INT) do
    coordinator.running = false
  end

  Signal.trap(:TERM) do
    exit
  end

  coordinator.run
end