Class: DeviceCommand
- Defined in:
- lib/replicant/commands/device_command.rb
Constant Summary collapse
- @@threads =
[]
Constants included from Styles
Styles::CONSOLE_WIDTH, Styles::REPL_OUT, Styles::STYLES
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(repl, args = nil, options = {}) ⇒ DeviceCommand
constructor
A new instance of DeviceCommand.
- #run ⇒ Object
- #usage ⇒ Object
- #valid_args? ⇒ Boolean
Methods inherited from Command
all, #execute, inherited, load, #name
Methods included from Styles
#create_style, #end_style, #styled_text
Constructor Details
#initialize(repl, args = nil, options = {}) ⇒ DeviceCommand
Returns a new instance of DeviceCommand.
5 6 7 8 9 |
# File 'lib/replicant/commands/device_command.rb', line 5 def initialize(repl, args = nil, = {}) super @process_muncher = ProcessMuncher.new(repl) @log_muncher = LogMuncher.new(repl) end |
Instance Method Details
#description ⇒ Object
11 12 13 |
# File 'lib/replicant/commands/device_command.rb', line 11 def description "set a default device to work with" end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# 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 ⇒ Object
15 16 17 |
# File 'lib/replicant/commands/device_command.rb', line 15 def usage "#{name} [<index>|<device_id>]" end |
#valid_args? ⇒ Boolean
19 20 21 |
# File 'lib/replicant/commands/device_command.rb', line 19 def valid_args? args.present? && /\S+/ =~ args end |