Class: Switchboard::Commands::Last

Inherits:
Switchboard::Command show all
Defined in:
lib/switchboard/commands/last/last.rb

Class Method Summary collapse

Methods inherited from Switchboard::Command

description, help, to_command, to_command_name

Class Method Details

.options(opts) ⇒ Object



8
9
10
11
# File 'lib/switchboard/commands/last/last.rb', line 8

def self.options(opts)
  super(opts)
  opts.on("--target=target", String, "Specifies the target to query.") { |v| OPTIONS["last.target"] = v }
end

.run!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/switchboard/commands/last/last.rb', line 13

def self.run!
  switchboard = Switchboard::Client.new do
    helper = Jabber::LastActivity::Helper.new(client)
    resp = helper.get_last_activity_from(jid = Jabber::JID.new(settings["last.target"]))

    status = " (#{resp.status})" if resp.status
    status ||= ""

    if jid.resource
      puts "#{jid} idle: #{resp.seconds} seconds" << status
    elsif jid.node
      puts "#{jid} last disconnected: " << (Time.new - resp.seconds).to_s << status
    else
      puts "#{jid} uptime: #{resp.seconds} seconds" << status
    end
  end

  switchboard.run!
end