Class: DeviceCommand

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

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#descriptionObject



197
198
199
# File 'lib/replicant/command.rb', line 197

def description
  "set a default device to work with"
end

#runObject



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/replicant/command.rb', line 209

def run
  default_device = if index?
    # user selected by index
    devices[args.to_i]
  else
    # user selected by device ID
    devices.detect { |d| d.id == args }
  end

  if default_device
    output "Setting default device to #{default_device.inspect}"
    @repl.default_device = default_device
  else
    output "No such device"
  end
end

#usageObject



201
202
203
# File 'lib/replicant/command.rb', line 201

def usage
  "#{name} [<index>|<device_id>]"
end

#valid_args?Boolean



205
206
207
# File 'lib/replicant/command.rb', line 205

def valid_args?
  args.present? && /\S+/ =~ args
end