Class: SnowmanIO::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/snowman-io/cli.rb

Overview

The command line interface for SnowmanIO.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ CLI

Returns a new instance of CLI.



13
14
15
# File 'lib/snowman-io/cli.rb', line 13

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/snowman-io/cli.rb', line 6

def options
  @options
end

Class Method Details

.runObject



8
9
10
11
# File 'lib/snowman-io/cli.rb', line 8

def self.run
  options = Options.new.parse!(ARGV)
  new(options).run
end

Instance Method Details

#runObject



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
45
46
# File 'lib/snowman-io/cli.rb', line 17

def run
  setup_logger

  # Self-pipe for deferred signal-handling (http://cr.yp.to/docs/selfpipe.html)
  self_read, self_write = IO.pipe

  %w(INT TERM USR1 USR2 TTIN).each do |sig|
    begin
      trap sig do
        self_write.puts(sig)
      end
    rescue ArgumentError
      puts "Signal #{sig} not supported"
    end
  end

  launcher = Launcher.new(options)

  begin
    launcher.start
    while readable_io = IO.select([self_read])
      signal = readable_io.first[0].gets.strip
      handle_signal(signal)
    end
  rescue Interrupt
    SnowmanIO.logger.info 'Shutting down'
    launcher.stop
    exit(0)
  end
end