Class: DevicesCommand

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

Instance Attribute Summary

Attributes inherited from Command

#args

Instance Method Summary collapse

Methods inherited from Command

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

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#descriptionObject



120
121
122
# File 'lib/replicant/command.rb', line 120

def description
  "print a list of connected devices"
end

#runObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/replicant/command.rb', line 124

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

  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

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

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