Class: MailRoom::CLI
- Inherits:
-
Object
- Object
- MailRoom::CLI
- Defined in:
- lib/mail_room/cli.rb
Overview
The CLI parses ARGV into configuration to start the coordinator with.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#coordinator ⇒ Object
Returns the value of attribute coordinator.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(args) ⇒ CLI
constructor
Initialize a new CLI instance to handle option parsing from arguments into configuration to start the coordinator running on all mailboxes.
-
#start ⇒ Object
Start the coordinator running, sets up signal traps.
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
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 41 42 43 44 |
# File 'lib/mail_room/cli.rb', line 11 def initialize(args) @options = {} OptionParser.new do |parser| parser. = [ "Usage: #{@name} [-c config_file]\n", " #{@name} --help\n" ].compact.join parser.on('-c', '--config FILE') do |path| [:config_path] = path end parser.on('-q', '--quiet') do [:quiet] = true end parser.on('--log-exit-as') do |format| [:exit_error_format] = 'json' unless format.nil? 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() self.coordinator = Coordinator.new(configuration.mailboxes) end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
5 6 7 |
# File 'lib/mail_room/cli.rb', line 5 def configuration @configuration end |
#coordinator ⇒ Object
Returns the value of attribute coordinator.
5 6 7 |
# File 'lib/mail_room/cli.rb', line 5 def coordinator @coordinator end |
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/mail_room/cli.rb', line 5 def @options end |
Instance Method Details
#start ⇒ Object
Start the coordinator running, sets up signal traps
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/mail_room/cli.rb', line 47 def start Signal.trap(:INT) do coordinator.running = false end Signal.trap(:TERM) do exit end coordinator.run rescue Exception => e # not just Errors, but includes lower-level Exceptions CrashHandler.new.handle(e, @options[:exit_error_format]) exit end |