Class: DevicesCommand

Inherits:
Command show all
Defined in:
lib/replicant/commands/devices_command.rb

Constant Summary

Constants included from Styles

Styles::CONSOLE_WIDTH, Styles::REPL_OUT, Styles::STYLES

Instance Attribute Summary

Attributes inherited from Command

#args

Instance Method Summary collapse

Methods inherited from Command

all, #execute, inherited, #initialize, load, #name, #usage

Methods included from Styles

#create_style, #end_style, #styled_text

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#descriptionObject



2
3
4
# File 'lib/replicant/commands/devices_command.rb', line 2

def description
  "print a list of connected devices"
end

#runObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/replicant/commands/devices_command.rb', line 6

def run
  adb = AdbCommand.new(@repl, "devices -l", :silent => true)
  device_lines = adb.execute.output.lines.to_a.reject do |line|
    line.strip.empty? || line.include?("daemon") || line.include?("List of devices")
  end

  device_lines.reject! { |l| l =~ /offline/ }
  device_ids = device_lines.map { |l| /([\S]+)\s+device/.match(l)[1] }
  device_products = device_lines.map { |l| /product:([\S]+)/.match(l).try(:[], 1) }

  device_names = device_lines.zip(device_ids).map do |l, id|
    /model:([\S]+)/.match(l).try(:[], 1) || detect_device_name(id)
  end

  device_indices = (1..device_ids.size).to_a
  devices = device_indices.zip(device_ids, device_names, device_products).map do |idx, id, name, product|
    Device.new(idx, id, humanize_name(name, product))
  end

  output ""
  output devices_string(devices)
  output ""
  devices
end