class DeviceCommand
Public Class Methods
new(repl, args = nil, options = {})
click to toggle source
Calls superclass method
Command::new
# File lib/replicant/commands/device_command.rb, line 5 def initialize(repl, args = nil, options = {}) super @process_muncher = ProcessMuncher.new(repl) @log_muncher = LogMuncher.new(repl) end
Public Instance Methods
description()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 11 def description "set a default device to work with" end
run()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 23 def run default_device = if index? && (1..devices.size).include?(args.to_i) # user selected by index devices[args.to_i - 1] else # user selected by device ID devices.detect { |d| d.id == args } end if default_device @repl.default_device = default_device output "Default device set to #{default_device.name}" # kill any existing threads putsd "Found #{@@threads.size} zombie threads, killing..." unless @@threads.empty? @@threads.select! { |t| t.exit } @@threads << @log_muncher.munch_logs do |logfile| observe_pid_changes(logfile) end output "Logs are available at #{LogMuncher::LOGFILE}" else output "No such device" end default_device end
usage()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 15 def usage "#{name} [<index>|<device_id>]" end
valid_args?()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 19 def valid_args? args.present? && /\S+/ =~ args end
Private Instance Methods
devices()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 58 def devices @devices ||= DevicesCommand.new(@repl, nil, :silent => true).execute end
index?()
click to toggle source
# File lib/replicant/commands/device_command.rb, line 54 def index? /^\d+$/ =~ args end
log_message!(o, message)
click to toggle source
# File lib/replicant/commands/device_command.rb, line 73 def log_message!(o, message) o.puts "*" * Styles::CONSOLE_WIDTH o.puts " #{message}" o.puts "*" * Styles::CONSOLE_WIDTH o.flush end
log_state_change!(o, change)
click to toggle source
# File lib/replicant/commands/device_command.rb, line 80 def log_state_change!(o, change) msg = "Detected change in device or target package\n" msg << "-" * Styles::CONSOLE_WIDTH msg << "\n --> device = #{@repl.default_device.name}" msg << "\n --> process = #{change}" log_message!(o, msg) end
observe_pid_changes(logfile)
click to toggle source
# File lib/replicant/commands/device_command.rb, line 62 def observe_pid_changes(logfile) @@threads << @process_muncher.scan_pid do |new_pid| @log_muncher.current_pid = new_pid if new_pid log_state_change!(logfile, "#{@repl.default_package} (pid = #{new_pid})") else log_state_change!(logfile, "<all>") end end end