Class: UpdateListeners::CLI

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

Constant Summary collapse

DEFAULT_SERIAL_DEVICE =
'/dev/tty.usbserial-A800ejOJ'
DEVICE_BAUD_RATE =
9600
ASCII_STX =
0x02
ASCII_ETX =
0x03
ASCII_US =
0x1F

Class Method Summary collapse

Class Method Details

.execute(stdout, arguments = []) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/update_listeners/cli.rb', line 14

def self.execute(stdout, arguments=[])
  @stdout = stdout
  parse_options!(arguments)

  device = BuildWatcher::ZigbeeDevice.new(@raw_device_string)
  device.project_quantity.times do |project_index|
    project_info = device.project_info(project_index)
    project = CodeFumes::Project.find(project_info.public_key)
    device.broadcast_status(project.public_key, project.build_status)
  end
end

.log(message, level = 'INFO') ⇒ Object



50
51
52
# File 'lib/update_listeners/cli.rb', line 50

def self.log(message, level = 'INFO')
  @stdout.puts "#{level}: #{message}"
end

.parse_options!(arguments) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/update_listeners/cli.rb', line 26

def self.parse_options!(arguments)
  OptionParser.new do |opts|
    opts.banner = <<-BANNER.gsub(/^          /,'')

      Usage: #{File.basename($0)} -d /dev/<some_device_string>

      Options are:
    BANNER
    opts.separator ""
    opts.on("-h", "--help",
            "Show this help message.") { @stdout.puts opts; exit }
    opts.on("-d", "--device [RAW_DEVICE]",
            "Override the default serial device used") {|device| @raw_device_string = device}

    opts.parse!(arguments)

    if @raw_device_string.nil? || @raw_device_string.empty?
      @stdout.puts opts
      exit
    end
  end

end