Class: WFA::Command
- Inherits:
-
Object
- Object
- WFA::Command
- Defined in:
- lib/wfa/command.rb
Instance Method Summary collapse
- #console(*args) ⇒ Object
- #heartbeats(device_tag, *args) ⇒ Object
- #identify(port, device_tag, *args) ⇒ Object
-
#initialize(args) ⇒ Command
constructor
A new instance of Command.
-
#list(*args) ⇒ Object
list configured devices.
-
#run(device_tag, *args) ⇒ Object
issue a command on the specified device.
-
#screen(device_tag, *args) ⇒ Object
open a screen on the specified device.
-
#shell(device_tag, *args) ⇒ Object
open a shell on the specified device.
- #start_wfa_command ⇒ Object
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wfa/command.rb', line 9 def initialize args @device_tag, @before_args, @after_args = extract_device_tag args option_parser.permute!(@before_args) @settings = {} load_settings unless no_cache @command = if @device_tag.nil? @before_args.shift || 'list' else if @before_args.count > 0 @before_args.shift elsif @after_args.count > 0 "run" else "shell" end end end |
Instance Method Details
#console(*args) ⇒ Object
46 47 48 49 |
# File 'lib/wfa/command.rb', line 46 def console *args puts "Try e.g.: http.get('devices').body" WFA::Console.new self, net end |
#heartbeats(device_tag, *args) ⇒ Object
76 77 78 79 |
# File 'lib/wfa/command.rb', line 76 def heartbeats device_tag, *args device = WFA::Device.by_tag(net, device_tag) or raise "no such device" puts device.heartbeats(net) end |
#identify(port, device_tag, *args) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/wfa/command.rb', line 81 def identify port, device_tag, *args device = WFA::Device.find(net, id) if device.update_remote(net, tag:device_tag.sub(/^@/,''), name:args.join(' ')) puts 'updated!' else puts 'update failed :(' end end |
#list(*args) ⇒ Object
list configured devices
52 53 54 55 56 |
# File 'lib/wfa/command.rb', line 52 def list *args # force a reload of the device list WFA::Device.fetch_and_cache_device_list(net) puts WFA::Device.all(net).select {|device| show_all || device.tag } end |
#run(device_tag, *args) ⇒ Object
issue a command on the specified device
71 72 73 74 |
# File 'lib/wfa/command.rb', line 71 def run device_tag, *args device = WFA::Device.by_tag(net, device_tag) or raise "no such device" shell_command "ssh -A workfrom@#{device.last_ip_addr} #{args.join(' ')}" end |
#screen(device_tag, *args) ⇒ Object
open a screen on the specified device
59 60 61 62 |
# File 'lib/wfa/command.rb', line 59 def screen device_tag, *args device = WFA::Device.by_tag(net, device_tag) or raise "no such device" shell_command "screen -t #{device.tag} -- ssh -A workfrom@#{device.last_ip_addr}" end |
#shell(device_tag, *args) ⇒ Object
open a shell on the specified device
65 66 67 68 |
# File 'lib/wfa/command.rb', line 65 def shell device_tag, *args device = WFA::Device.by_tag(net, device_tag) or raise "no such device" shell_command "ssh -A workfrom@#{device.last_ip_addr}" end |
#start_wfa_command ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/wfa/command.rb', line 30 def start_wfa_command case @command when 'identify' public_send @command, *@before_args, @device_tag, *@after_args else public_send @command, @device_tag, *@after_args end save_settings rescue NoMethodError => e $stderr.puts "no such command: #{@command}" rescue Faraday::ClientError => e $stderr.puts e. rescue StandardError => e $stderr.puts e. end |